RFR: 8300979: Lazily initialize (byte, char)arr in java.io.DataInputStream [v3]

Eirik Bjorsnos duke at openjdk.org
Thu Mar 23 13:54:46 UTC 2023


On Wed, 22 Mar 2023 10:12:26 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposed to lazily initialize the scratch arrays only if/when needed.
>
> Per Minborg has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - Merge branch 'dis-lazy' of https://github.com/minborg/jdk into dis-lazy
>  - Update src/java.base/share/classes/java/io/DataInputStream.java
>    
>    Co-authored-by: Eirik Bjorsnos <eirbjo at gmail.com>
>  - Merge branch 'master' into dis-lazy
>  - Remove redundant initilizers
>  - Lazily initialize (byte, char)arr in java.io.DataInputStream

I cannot explain why, but the changes suggested in this PR seem to introduce a small, but significant performance regression on the `DataInputStreamTest.readInt` benchmark:

Baseline:


Benchmark                    Mode  Cnt  Score   Error  Units
DataInputStreamTest.readInt  avgt   20  5.563 ± 0.037  us/op


PR:


Benchmark                    Mode  Cnt  Score   Error  Units
DataInputStreamTest.readInt  avgt   20  6.021 ± 0.020  us/op


The reason this puzzles me is that the `readInt` benchmark don't involve the UTF code paths at all. So why would it become slower, just because two fields are no longer initialized with the default arrays?

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

PR Comment: https://git.openjdk.org/jdk/pull/13121#issuecomment-1481235244


More information about the core-libs-dev mailing list