RFR: 8358533: Improve performance of java.io.Reader.readAllLines [v7]
Roger Riggs
rriggs at openjdk.org
Wed Jul 2 13:46:39 UTC 2025
On Fri, 27 Jun 2025 23:00:04 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> src/java.base/share/classes/java/io/Reader.java line 504:
>>
>>> 502: }
>>> 503: if (fragLen >= cb.length/2) {
>>> 504: // allocate larger buffer and copy chars to beginning
>>
>> It might be designed to use a more conservative resizing approach, for example, **cb.length + TRANSFER_BUFFER_SIZE**, rather than exponential doubling, more in line with how resizing is handled in string builder. not a very strong opinion though :-)
>
>> [...] more in line with how resizing is handled in string builder
>
> Looks like `StringBuilder` eventually calls `ArraysSupport.newLength(int,int.int)`. This is probably worth checking out.
On the call to ArraysSupport.newLength(curr, min, preferred).
This will double the size (preferred) until it runs past SOFT_MAX_ARRAY_LENGTH.
Then it starts growing by minGrowth, it should probably be smaller; something that will allow it to get pretty close to SOFT_MAX_ARRAY_LENGTH before throwing OOME. But still large enough to allow efficient reads.
Maybe 4k, or 8k, or 16k.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2180106662
More information about the core-libs-dev
mailing list