RFR: 8276779: (ch) InputStream returned by Channels.newInputStream should have fast path for SelectableChannels [v17]

Markus KARG duke at openjdk.java.net
Sat Nov 27 16:32:37 UTC 2021


> As proposed in JDK-8265891, this PR provides an implementation for `Channels.newInputStream().transferTo()` which provide superior performance compared to the current implementation. This PR is a spin-off from https://github.com/openjdk/jdk/pull/4263 and deliberately concentrates **only** on `FileChannel`s. Other types of channels will be discussed in future PRs.
> 
> * Prevents transfers through the JVM heap as much as possibly by offloading to deeper levels via NIO, hence allowing the operating system to optimize the transfer.
> 
> Using JMH I have benchmarked both, the original implementation and this implementation, and (depending on the used hardware and use case) performance change was approx. doubled performance. A rather similar approach in different use casse was recently implemented by https://github.com/openjdk/jdk/pull/5097 which was reported by even provide 5x performance (https://github.com/openjdk/jdk/pull/5097#issuecomment-897271997).
> 
> **Update:** This sub-issue *only* defines the work to be done to implement JDK-8265891 *solely* for the particular case of FileChannel.transferTo(WriteableByteChannel), including special treatment of SelectableByteChannel, as the `master` branch already contains code to handle the specific case of FileChannel.transferTo(FileChannel).

Markus KARG has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:

 - Closing non-claimed resourced
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Closing all claimed resources
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Tests IllegalBlockingModeException
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - JavaDoc proposal by Alan Bateman
 - 8265891: ChannelInputStream.transferTo() uses FileChannel.transferTo()
   
   This sub-issue defines the work to be done to implement JDK-8265891 solely for the particular case of FileChannel.transferTo(WritableByteChannel), including special treatment of SelectableByteChannel.
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/5179/files
  - new: https://git.openjdk.java.net/jdk/pull/5179/files/c4904cac..5a2b441f

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=5179&range=16
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=5179&range=15-16

  Stats: 23816 lines in 438 files changed: 14338 ins; 6199 del; 3279 mod
  Patch: https://git.openjdk.java.net/jdk/pull/5179.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/5179/head:pull/5179

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


More information about the nio-dev mailing list