RFR: 8339874: Avoid duplicate checking of trailing slash in ZipFile.getZipEntry [v2]

Eirik Bjørsnøs eirbjo at openjdk.org
Wed Sep 11 07:13:20 UTC 2024


> Please review this PR which speeds up `ZipFile.getZipEntry` by removing slash-checking logic which is already taking place during lookup in `ZipFile.Source.getEntryPos`. 
> 
> `ZipFile.Source.getEntryPos` includes logic to match a lookup for "name" against a directory entry "name/" (with a trailing slash). However, only the CEN position is currently returned, so `ZipFile.getZipEntry` needs to re-read the name from the CEN and determine if a trailing slash needs to be appended to the name of the returned `ZipEntry`.
> 
> By letting `ZipFile.Source.getEntryPos` return the resolved name along with the CEN position (in a new record `EntryPos`), `ZipFile.getZipEntry` can now instead use the already resolved name. 
> 
> This results in a nice ~18% speedup in the `ZipFileGetEntry.getEntryHit` micro:
> 
> Baseline:
> 
> 
> Benchmark                    (size)  Mode  Cnt   Score   Error  Units
> ZipFileGetEntry.getEntryHit     512  avgt   15  63.713 ? 2.645  ns/op
> ZipFileGetEntry.getEntryHit    1024  avgt   15  67.405 ? 1.474  ns/op
> 
> 
> PR:
> 
> 
> Benchmark                    (size)  Mode  Cnt   Score   Error  Units
> ZipFileGetEntry.getEntryHit     512  avgt   15  52.027 ? 2.669  ns/op
> ZipFileGetEntry.getEntryHit    1024  avgt   15  55.211 ? 1.169  ns/op
> 
> 
> This purely a cleanup and optimization PR, no functional tests are changed or added.

Eirik Bjørsnøs has updated the pull request incrementally with three additional commits since the last revision:

 - Make UTF8ZipCoder.hasTrailingSlash private and remove the unused ZipCoder.hasTrailingSlash with the associated slashBytes() method and slashBytes field
 - Revert signature change in ZipFile.getZipEntry so iterators won't need to wrap arguments in as EntryPos instances
 - Revert change in access modifier for ZipCoder.checkedHash

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/20939/files
  - new: https://git.openjdk.org/jdk/pull/20939/files/6c9f09b4..679ee585

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=20939&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=20939&range=00-01

  Stats: 33 lines in 2 files changed: 0 ins; 27 del; 6 mod
  Patch: https://git.openjdk.org/jdk/pull/20939.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/20939/head:pull/20939

PR: https://git.openjdk.org/jdk/pull/20939


More information about the core-libs-dev mailing list