RFR: 8265891: ChannelInputStream.transferTo() uses FileChannel.transferTo() [v10]

Markus KARG github.com+1701815+mkarg at openjdk.java.net
Tue Sep 7 16:05:09 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).

Markus KARG has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains 11 new commits since the last revision:

 - 8265891: ChannelInputStream.transferTo() uses FileChannel.transferTo(WritableByteChannel)
   
   As suggested in 8265891 this change implements a performance optimization
   for ChannelInputStream.transferTo(): It uses
   FileChannel.transferTo(WritableByteChannel) in case the source channel
   actually is a FileChannel and the target channel is a
   WritableByteChannel, as in that case,
   the actual work of transferring bytes can potentially get offloaded to the
   operating system / file system.
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Added comma after year in copyright
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Copyright (C) 2021 instead of 2014, 2021
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Replaced 'point' by 'position' in comments
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Moved TransferTo.java from test/jdk/sun/nio/ch/ChannelInputStream/ to test/jdk/java/nio/channels/Channels/
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Redeced line lenght; maximum length now is 115 characters
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Removed static modifiers on interfaces
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Removed unused imports
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Renamed ifOutIsNullThenNpeIsThrows to testNullPointerException
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - Renamed contents() to testStreamContents()
   
   Signed-off-by: Markus Karg <markus at headcrashing.eu>
 - ... and 1 more: https://git.openjdk.java.net/jdk/compare/a507fd77...e76caa46

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/5179/files
  - new: https://git.openjdk.java.net/jdk/pull/5179/files/a507fd77..e76caa46

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

  Stats: 28 lines in 1 file changed: 7 ins; 10 del; 11 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