RFR: 4926314: Optimize Reader.read(CharBuffer) [v3]

Brian Burkhalter bpb at openjdk.java.net
Mon Feb 8 21:46:55 UTC 2021


On Tue, 5 Jan 2021 17:44:20 GMT, Philippe Marschall <github.com+471021+marschall at openjdk.org> wrote:

>> Implement three optimiztations for Reader.read(CharBuffer)
>> 
>> * Add a code path for heap buffers in Reader#read to use the backing array instead of allocating a new one.
>> * Change the code path for direct buffers in Reader#read to limit the intermediate allocation to `TRANSFER_BUFFER_SIZE`.
>> * Implement `InputStreamReader#read(CharBuffer)` and delegate to `StreamDecoder`.
>> * Implement `StreamDecoder#read(CharBuffer)` and avoid buffer allocation.
>
> Philippe Marschall has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update copyright years

src/java.base/share/classes/java/io/Reader.java line 198:

> 196:         } else {
> 197:             int remaining = target.remaining();
> 198:             char cbuf[] = new char[Math.min(remaining, TRANSFER_BUFFER_SIZE)];

As `cbuf` for the off-heap case is used in a synchronized block, is there the opportunity for some sort of cached array here and would it help?

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

PR: https://git.openjdk.java.net/jdk/pull/1915


More information about the nio-dev mailing list