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

Markus KARG github.com+1701815+mkarg at openjdk.java.net
Wed Aug 25 16:21:33 UTC 2021


On Tue, 24 Aug 2021 20:55:05 GMT, Markus KARG <github.com+1701815+mkarg at openjdk.org> wrote:

>> 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 https://github.com/openjdk/jdk/pull/5179 and deliberately concentrates **only** on the case where both, source **and** target, are actually `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 updated the pull request incrementally with one additional commit since the last revision:
> 
>   Simplified copy loop
>   
>   Signed-off-by: Markus Karg <markus at headcrashing.eu>

> > > There are 3 PRs open, I'll ignore #4263 and #5179 for now.
> > 
> > 
> > Yes please ignore them for now. The other two PRs are suspendend as they cover bigger pictures and will be resumed by me _later_.
> 
> Okay. The implementation changes in the current patch ([205b9b2](https://github.com/openjdk/jdk/commit/205b9b21e003937f91311eb91d7671e0810684bb)) look good. I think we will need to iterate on the test.

Ok so I will do as Brian said and include a test case with random initial positions. Note that my test will do that with the default case, too, so maybe someone should do that for the original test of the default implementation, too, to stay in sync.

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

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


More information about the nio-dev mailing list