RFR: 8268435: (ch) ChannelInputStream could override readAllBytes
Brian Burkhalter
bpb at openjdk.java.net
Thu Sep 23 02:04:00 UTC 2021
On Thu, 23 Sep 2021 01:52:31 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> This change would override `readAllBytes()` and `readNBytes(int)` in `ChannelInputStream` thereby improving performance for all but smaller streams.
Throughput measured without the change for various stream lengths was
Benchmark (length) Mode Cnt Score Error Units
ChannelInputStream.readAllBytes 1000 thrpt 10 418393.824 ± 2969.676 ops/s
ChannelInputStream.readAllBytes 10000 thrpt 10 196087.387 ± 1947.272 ops/s
ChannelInputStream.readAllBytes 100000 thrpt 10 29089.090 ± 430.841 ops/s
ChannelInputStream.readAllBytes 1000000 thrpt 10 2534.655 ± 5.373 ops/s
ChannelInputStream.readAllBytes 10000000 thrpt 10 209.193 ± 1.106 ops/s
ChannelInputStream.readAllBytes 100000000 thrpt 10 20.010 ± 0.047 ops/s
ChannelInputStream.readAllBytes 1000000000 thrpt 10 1.455 ± 0.204 ops/s
ChannelInputStream.readNBytes 1000 thrpt 10 544002.863 ± 1900.158 ops/s
ChannelInputStream.readNBytes 10000 thrpt 10 421766.791 ± 2928.367 ops/s
ChannelInputStream.readNBytes 100000 thrpt 10 57035.078 ± 214.834 ops/s
ChannelInputStream.readNBytes 1000000 thrpt 10 5855.087 ± 52.283 ops/s
ChannelInputStream.readNBytes 10000000 thrpt 10 427.560 ± 2.925 ops/s
ChannelInputStream.readNBytes 100000000 thrpt 10 40.118 ± 0.091 ops/s
ChannelInputStream.readNBytes 1000000000 thrpt 10 3.315 ± 0.434 ops/s
and with the change in place was
Benchmark (length) Mode Cnt Score Error Units
ChannelInputStream.readAllBytes 1000 thrpt 10 337785.548 ± 2702.517 ops/s
ChannelInputStream.readAllBytes 10000 thrpt 10 245969.721 ± 1362.465 ops/s
ChannelInputStream.readAllBytes 100000 thrpt 10 75736.303 ± 321.443 ops/s
ChannelInputStream.readAllBytes 1000000 thrpt 10 8835.464 ± 73.547 ops/s
ChannelInputStream.readAllBytes 10000000 thrpt 10 370.141 ± 0.675 ops/s
ChannelInputStream.readAllBytes 100000000 thrpt 10 34.029 ± 0.152 ops/s
ChannelInputStream.readAllBytes 1000000000 thrpt 10 3.414 ± 0.032 ops/s
ChannelInputStream.readNBytes 1000 thrpt 10 354884.272 ± 2264.808 ops/s
ChannelInputStream.readNBytes 10000 thrpt 10 296775.457 ± 4296.873 ops/s
ChannelInputStream.readNBytes 100000 thrpt 10 120579.221 ± 374.626 ops/s
ChannelInputStream.readNBytes 1000000 thrpt 10 18079.568 ± 109.945 ops/s
ChannelInputStream.readNBytes 10000000 thrpt 10 860.772 ± 2.333 ops/s
ChannelInputStream.readNBytes 100000000 thrpt 10 69.266 ± 0.293 ops/s
ChannelInputStream.readNBytes 1000000000 thrpt 10 6.840 ± 0.016 ops/s
In effect, degraded performance for very small lengths is traded off against better performance for larger lengths. Note however that the `readNBytes()` measurements were made for `len = length/2` and so are less telling. Otherwise said, the `readAllBytes()` results are more straightforwardly interpreted. Adding a threshold was not investigated.
Unfortunately this is mostly code duplication from `FileInputStream`. It would be better if there were a common location where the implementation could be placed and used by both cases.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5645
More information about the nio-dev
mailing list