On Wed, 18 Jun 2025 16:57:22 GMT, Brian Burkhalter <b...@openjdk.org> wrote:

>> src/java.base/share/classes/java/io/Reader.java line 455:
>> 
>>> 453:         List<String> lines = new ArrayList<String>();
>>> 454: 
>>> 455:         StringBuilder sb = new StringBuilder(82);
>> 
>> Is there a reason for this pre-allocation? If the whole content is smaller 
>> than 8192 in size, this allocation would be redundant because we are going 
>> through the string constructor path.
>
>> Is there a reason for this pre-allocation?
> 
> What would you suggest? Start with a smaller allocation and increase it if 
> needed? There is no possibility of knowing the length of the stream.

As this PR explicitly targets performance and as the aim of this method is to 
keep **all** content in-memory anyways, I wonder if it would be acceptable and 
even faster to pre-allocate `new StringBuilder(TRANSFER_BUFFER_SIZE)`? In the 
end, this allocation is just temporary.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2156717996

Reply via email to