On Fri, 12 Feb 2021 09:18:10 GMT, Philippe Marschall <github.com+471021+marsch...@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 two > additional commits since the last revision: > > - Replace c-style array declarations > - Share work buffer between #skip and #read src/java.base/share/classes/java/io/Reader.java line 221: > 219: // if the last call to read returned -1 or the > number of bytes > 220: // requested have been read then break > 221: } while (n >= 0 && remaining > 0); The code for case that the char buffer has a backing array looks okay but I'm not sure about the direct buffer/other cases. One concern is that this is a read method, not a transferXXX method so we shouldn't be calling the underlying read several times. You'll see what I mean if you consider the scenario where you read < rem, then read again and the second read blocks or throws. I'l also concerned about "workBuffer" adding more per-stream footprint for cases where skip or read(CB) is used. Objects such as InputStreamReader are already a problem due to the underlying stream decoder. ------------- PR: https://git.openjdk.java.net/jdk/pull/1915