RFR: 8305744: (ch) InputStream returned by Channels.newInputStream should have fast path for ReadbleByteChannel/WritableByteChannel [v3]

Markus KARG duke at openjdk.org
Sun Apr 9 15:11:42 UTC 2023


On Sat, 8 Apr 2023 06:51:29 GMT, Alan Bateman <alanb at openjdk.org> wrote:

> It would be helpful if there were some benchmarks or something to that shows which cases this helps. The current description isn't very clear on which case there is 2.5% benefit.

I assume the *biggest* benefit would occur when running on special I/O hardware with custom OS drivers and custom Channel implementations (like forwarding analog samples from an ADC input to a DAC output, e. g. in audio devices). As I do not own such a device, and as the *biggest* benefit should not be the basis for decision-making, I haven choosen the opposite for my benchmark: I measured the code that might benefit *the least* from the optimization: Java-Heap-to-Java-Heap. Still the result is ~2.5% benefit.

@Benchmark
public void ChannelInputStream_transferTo() throws Throwable {
    var is = Channels.newInputStream(Channels.newChannel(new ByteArrayInputStream(new byte[1024 * 1024 * 1024])));
    var os = Channels.newOutputStream(Channels.newChannel(new ByteArrayOutputStream(1024 * 1024 * 1024)));
    is.transferTo(os);
}


Sandbox.ChannelInputStream_transferTo  thrpt   25  3,794 ┬▒ 0,095  ops/s -- incl. optimization (i. e. using ByteBuffer)
Sandbox.ChannelInputStream_transferTo  thrpt   25  3,703 ┬▒ 0,098  ops/s -- excl. optimization (i. e. using byte[])

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

PR Comment: https://git.openjdk.org/jdk/pull/13387#issuecomment-1501150543


More information about the nio-dev mailing list