RFR: 8342040: Further improve entry lookup performance for multi-release JARs

Eirik Bjørsnøs eirbjo at openjdk.org
Mon Oct 14 14:37:22 UTC 2024


On Mon, 14 Oct 2024 11:01:21 GMT, Eirik Bjørsnøs <eirbjo at openjdk.org> wrote:

> Please review this PR which speeds up `JarFile::getEntry` lookup significantly for multi-release JAR files.
> 
> The changes in this PR are motivated by the following insights:
> 
> * `META-INF/versions/` is sparsely populated.
> * Most entries are not versioned
> * The number of unique versions for each versioned entry is small
> * Many JAR files are 'accidentally' multi-release; they use the feature to hide `module-info.class` from Java 8.
> 
> Instead of  performing one lookup for every version identified in the JAR, this PR narrows the version search down to only the number of versions found for the entry being looked up, which will most often be zero. This speeds up lookup for non-versioned entries, and provides a more targeted search for versioned entries.
> 
> An alternative approach could be to normalize the hash code to use the none-versioned name such that versioned and non-versioned names would be resolved in the same lookup. This was quickly abandoned since the code changes were intrusive and mixed too many JAR specific concerns into `ZipFile`.
> 
> Testing: The existing `JarFileGetEntry` benchmark is updated to optionally test a multi-release JAR file with one versioned entry for `module-info.class` plus two other versioned class files for two distinct versions. Performance results in [first comment](#issuecomment-2410901754).
> 
> Running `ZipFileOpen` on a multi-release JAR did not show a significat difference between this PR and mainline. 
> 
> The JAR and ZIP tests are run locally. GHA results green. The `noreg-perf` label is added in JBS.

Performance results:

Baseline:


JarFileGetEntry.getEntryHit           false    1024  avgt   15   64.619 ? 6.633  ns/op
JarFileGetEntry.getEntryHit            true    1024  avgt   15  301.770 ? 4.819  ns/op
JarFileGetEntry.getEntryHitUncached   false    1024  avgt   15   82.030 ? 2.057  ns/op
JarFileGetEntry.getEntryHitUncached    true    1024  avgt   15  327.966 ? 3.092  ns/op
JarFileGetEntry.getEntryMiss          false    1024  avgt   15   27.937 ? 0.982  ns/op
JarFileGetEntry.getEntryMiss           true    1024  avgt   15  267.280 ? 2.196  ns/op
JarFileGetEntry.getEntryMissUncached  false    1024  avgt   15   53.214 ? 1.085  ns/op
JarFileGetEntry.getEntryMissUncached   true    1024  avgt   15  290.904 ? 2.359  ns/op


PR:


Benchmark                              (mr)  (size)  Mode  Cnt   Score   Error  Units
JarFileGetEntry.getEntryHit           false    1024  avgt   15  63.311 ? 3.014  ns/op
JarFileGetEntry.getEntryHit            true    1024  avgt   15  71.333 ? 1.510  ns/op
JarFileGetEntry.getEntryHitUncached   false    1024  avgt   15  80.401 ? 0.516  ns/op
JarFileGetEntry.getEntryHitUncached    true    1024  avgt   15  94.810 ? 1.136  ns/op
JarFileGetEntry.getEntryMiss          false    1024  avgt   15  26.717 ? 0.276  ns/op
JarFileGetEntry.getEntryMiss           true    1024  avgt   15  45.677 ? 0.412  ns/op
JarFileGetEntry.getEntryMissUncached  false    1024  avgt   15  53.122 ? 0.954  ns/op
JarFileGetEntry.getEntryMissUncached   true    1024  avgt   15  66.583 ? 0.425  ns/op

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

PR Comment: https://git.openjdk.org/jdk/pull/21489#issuecomment-2410901754


More information about the security-dev mailing list