RFR: 8294696 - BufferedInputStream.transferTo should drain buffer when mark set [v5]
Markus KARG
duke at openjdk.org
Mon Oct 31 13:01:24 UTC 2022
On Mon, 31 Oct 2022 09:52:06 GMT, Alan Bateman <alanb at openjdk.org> wrote:
> > **TL;DR:** Your optimization is now contained in this PR and outperforms the previous code. Nevertheless I plead for Alternative C (double buffering) instead, which is even faster but much simpler.
> You had dismissed this previously so it's useful to have results now to compare. I agree it's much simpler, it can probably use Arrays.copyOfRange too.
Sorry for that. Unless I actually tested, I was unaware how slow Alternative B actually is (in fact it was quite surprising that `Arrays.fill` apparently is implemented in pure Java while `System.arraycopy` is native). So let's go on with Alternative C + `Arrays.copyOfRange`! :-)
> For the results, can you say what the underlying input stream is and what the target output stream is? Also it would be useful to get a baseline. I suspect you have that, it's just not pasted in the table above.
The underlying input stream is `ByteArrayInputStream` wrapping 1 MB byte array, the output stream is `ByteArrayOutputStream`. So the test is not I/O-bound, hence it is clearly focusing on the actual difference Alternatives B/C. Yes, I do have a baseline. It is the original code without *any* safety against poisoning and leaking and the numbers are shown below. I have not published it before, because they are not perfectly comparable: A Windows Update happened after the above runs, and before this run, and my laptop feels to behave somewhat different since then. Sorry for that, but I had no time to repeat the full four hours test suite, and I think the numbers are good enough for our decision pro Alternative C.
Benchmark (bufSize) (posPercent) Mode Cnt Score Error Units
BufferedInputStreamTransferToPerformance.transferTo 8192 0 thrpt 25 4197,126 ┬▒ 627,973 ops/s
BufferedInputStreamTransferToPerformance.transferTo 8192 10 thrpt 25 2615,802 ┬▒ 251,678 ops/s
BufferedInputStreamTransferToPerformance.transferTo 8192 90 thrpt 25 3140,941 ┬▒ 575,787 ops/s
BufferedInputStreamTransferToPerformance.transferTo 8192 100 thrpt 25 4603,691 ┬▒ 12,127 ops/s
BufferedInputStreamTransferToPerformance.transferTo 1048576 0 thrpt 25 3539,737 ┬▒ 59,913 ops/s
BufferedInputStreamTransferToPerformance.transferTo 1048576 10 thrpt 25 4790,750 ┬▒ 63,090 ops/s
BufferedInputStreamTransferToPerformance.transferTo 1048576 90 thrpt 25 43273,624 ┬▒ 1784,369 ops/s
BufferedInputStreamTransferToPerformance.transferTo 1048576 100 thrpt 25 1693553,210 ┬▒ 21249,108 ops/s
-------------
PR: https://git.openjdk.org/jdk/pull/10525
More information about the core-libs-dev
mailing list