JDK-8193066 : Avoid use of capturing lambdas in JarFile
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 10,11,14,15
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-12-05
  • Updated: 2020-05-14
  • Resolved: 2020-05-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15 b23Fixed
Related Reports
Relates :  
Description
Capturing lambdas are relatively expensive, and should be avoided if possible. Anonymous local functions, too.

All lambdas used in the interaction between JarFile and ZipFile can be avoided by having ZipFile call a shared secret in JarFile to create a JarFileEntry when appropriate. This removes an allocation per lookup.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/e8cebbd8dfac User: redestad Date: 2020-05-11 20:14:19 +0000
11-05-2020

This improves on .01 by not needing to add an overrideable protected method: http://cr.openjdk.java.net/~redestad/scratch/zip_entryFor.02/ - microbenchmark results look similar to .01.
10-05-2020

A possible fix for this is to get rid of the lambdas entirely by introducing a protected method to create an implementation-suitable ZipEntry: http://cr.openjdk.java.net/~redestad/scratch/zip_entryFor.01/ This achieves a small speed-up on JarFile.getEntry misses, and reduces allocations on all lookups. While speed-up is in the nanoseconds on highly optimized code, the speed-up is quite large when interpreting, from around 1.8us/op to 1.5us/op in one test - thus startup impact might be significant. While the internal complexity is reduced somewhat, the new protected methods require a CSR
10-05-2020