RFR: 8305744: (ch) InputStream returned by Channels.newInputStream should have fast path for ReadbleByteChannel/WritableByteChannel [v3]
Markus KARG
duke at openjdk.org
Wed Aug 2 16:09:54 UTC 2023
On Tue, 20 Jun 2023 22:15:13 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>>> ```java
>>> @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);
>>> }
>>> ```
>>
>> The above benchmark method includes the construction of 6 objects in the measurement. I think it would be more representative of the effect of the change to do something like this:
>>
>>
>> private static final int SIZE = 1024*1024*1024;
>>
>> ByteArrayInputStream in = new ByteArrayInputStream(new byte[SIZE]);
>> ByteArrayOutputStream out = new ByteArrayOutputStream(SIZE);
>>
>> ReadableByteChannel rbc = Channels.newChannel(in);
>> WritableByteChannel wbc = Channels.newChannel(out);
>>
>> InputStream is = Channels.newInputStream(rbc);
>> OutputStream os = Channels.newOutputStream(wbc);
>>
>> @Setup
>> public void setup() {
>> in.mark(SIZE + 1);
>> }
>>
>> @Benchmark
>> public void ChannelInputStream_transferTo() throws Throwable {
>> is.transferTo(os);
>> in.reset();
>> out.reset();
>> }
>
>> @Setup
>> public void setup() {
>> in.mark(SIZE + 1);
>> }
>
> In my benchmark example the above code is unneeded.
@bplb I would be glad if we could continue with the review of this PR.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13387#issuecomment-1662494403
More information about the nio-dev
mailing list