RFR: 8358533: Improve performance of java.io.Reader.readAllLines [v3]

Roger Riggs rriggs at openjdk.org
Tue Jun 24 19:15:28 UTC 2025


On Tue, 24 Jun 2025 19:00:42 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>>> My suggestion is to call `new StringBuilder(0)`
>> 
>> So changed in 8ccfd54.
>
>> When a partial line is left in the transfer buffer, copy it to the beginning of the buffer and read more characters for the remaining size of the buffer.
> 
> The "transfer buffer" is the character array `cb`, right?
> 
>> You might still need a fallback for really long lines (> transfer buffer size), but that might be more easily handled by reallocating the transfer buffer to make it larger.
> 
> The size of the array `cb` is not intended to be commensurate with line length, but rather to allow reading multiple lines thereby cutting down the nunber of reads.

Right, but some line might be longer than the transfer buffer size, so some mechanism is needed to assemble a longer line. Whether its a separate buffer (like SB) or just a bigger transfer buffer. One possibility is to copy the remaining fragment of a line to a new transfer buffer (maybe twice the size).

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

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


More information about the core-libs-dev mailing list