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

Brett Okken github.com+2996845+bokken at openjdk.java.net
Sun Jan 10 02:01:59 UTC 2021

On Sat, 9 Jan 2021 23:06:22 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:
>   Add unit tests
>   - add unit test for Reader#read(CharBuffer)
>   - add unit test for InputStreamReader#reader(CharBuffer)
>   - test with both on-heap and off-heap buffers

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)];

Would there be value in making this a (lazily created) member variable? That would allow a single instance to be reused. It seems likely that, if one call is made with a direct CharBuffer, subsequent calls will also be made with direct instances (probably same instance?).


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

More information about the core-libs-dev mailing list