RFR 8193832: Performance of InputStream.readAllBytes() could be improved

Peter Levart peter.levart at gmail.com
Fri Dec 22 09:21:27 UTC 2017

Hi Brian,

On 12/21/2017 09:44 PM, Brian Burkhalter wrote:
> On Dec 21, 2017, at 11:44 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>>> I concur that this horse is almost dead from the beatings but since I already hacked up Peter’s suggestion which eliminates intermediate copies I might as well hang it out there (see below).
>> That looks ok to me, i think keeping the buf allocation at the top of the loop tends to simplify the reasoning.
> Agreed. Here’s the hopefully final version:
> http://cr.openjdk.java.net/~bpb/8193832/webrev.04/
> I think the test case all the cases, i.e., possible data lengths, aside from the OOME case.

I think this looks good. No more suggestions from my side for this 
patch. As Paul notes, it would be interesting to see if using 
Unsafe.allocateUninitializedArray() to allocate the final array (and 
intermediate buffers too) has a measurable impact.

Regards, Peter

>>>> I do have one follow on investigation we discussed off list that is worth measuring. At the end use the Unsafe array allocation with no zeroing, since the resulting array will be fully written into. This might result in an observable improvement.
>>> I’ve not forgotten about that but do not know whether we want to include it as part of this issue or a subsequent one.
>> I suggest a follow on investigation.
> I’ll file an issue.
> Thanks,
> Brian

More information about the core-libs-dev mailing list