RFR: 8358533: Improve performance of java.io.Reader.readAllLines
Chen Liang
liach at openjdk.org
Fri Jun 20 15:54:31 UTC 2025
On Thu, 19 Jun 2025 10:53:14 GMT, Markus KARG <duke at openjdk.org> wrote:
>>> 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.
My suggestion is to call `new StringBuilder(0)` as it is possible this is completely unused because we always hit the `eol && sb.length() == 0` path below.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25863#discussion_r2159289340
More information about the core-libs-dev
mailing list