RFR: 8265891: ChannelInputStream.transferTo() uses FileChannel.transferTo()

Markus KARG github.com+1701815+mkarg at openjdk.java.net
Thu Aug 19 06:23:44 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).

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

Commit messages:
 - 8265891: ChannelInputStream.transferTo() uses FileChannel.transferTo()

Changes: https://git.openjdk.java.net/jdk/pull/5179/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=5179&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8265891
  Stats: 449 lines in 4 files changed: 369 ins; 76 del; 4 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