8352075: Perf regression accessing fields #24713
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This optimization is a followup to #24290 trying to reduce the performance regression in some scenarios introduced in https://bugs.openjdk.org/browse/JDK-8292818
Iteration through the field stream of several variable-length-encoded items is limited by inherent dependency of fully decoding the field before knowing the position of next field. On the critical codepath addressed by this PR, only the name and signature indices from are used though.
Inspired by the Varint-GB and Varint-G81U encodings, the idea of this change is in adding a control stream to the stream of field infos; each field uses one byte of this control stream, and currently the lower 6 bits encode the length of the encoded field, allowing more efficient skipping through the stream. The most significant bit duplicates the injected field flag (name/signature lookup requires that), one bit is currently unused.
My measurements on the attached reproducer
(the
jdk25-masterabove already contains JDK-8353175)So in case of the synthetic reproducer we're already on the level of JDK 17. However, the undisclosed production-grade reproducer still shows regression, so there is still space for optimization.
About the downsides: This PR increases the consumption by 1 byte for each field in loaded classes. I've executed some tests on a simple Spring Boot application with 6800 instance classes loaded -> about 16k fields in total, with NMT on; the memory usage (Class.Metadata.used) seems to have grown by 32kB; this discrepancy could be investigated later on.
Architecturally, I had to remove
constness from some methods onFieldStreamBase.I think that the memory usage difference is negligible in the practice; if this matters, though, I have implemented two more optimizations in https://github.com/rvansa/jdk/tree/JDK-8352075-dev that should give the byte back, in average. However these optimizations have reduced performance in all of the benchmarks, hence I would prefer not to apply these.
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24713/head:pull/24713$ git checkout pull/24713Update a local copy of the PR:
$ git checkout pull/24713$ git pull https://git.openjdk.org/jdk.git pull/24713/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24713View PR using the GUI difftool:
$ git pr show -t 24713Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24713.diff
Using Webrev
Link to Webrev Comment