Skip to content

Conversation

@rvansa
Copy link

@rvansa rvansa commented Apr 17, 2025

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

hyperfine -w 50 -r 100 '/path/to/jdk-17/bin/java -cp /tmp CCC'
Benchmark 1: /path/to/jdk-17/bin/java -cp /tmp CCC
  Time (mean ± σ):      51.3 ms ±   2.8 ms    [User: 44.7 ms, System: 13.7 ms]
  Range (min … max):    45.1 ms …  53.9 ms    100 runs
hyperfine -w 50 -r 100 '/path/to/jdk25-master/bin/java -cp /tmp CCC'
Benchmark 1: /path/to/jdk25-master/bin/java -cp /tmp CCC
  Time (mean ± σ):      78.2 ms ±   1.0 ms    [User: 74.6 ms, System: 17.3 ms]
  Range (min … max):    73.8 ms …  79.7 ms    100 runs

(the jdk25-master above already contains JDK-8353175)

hyperfine -w 50 -r 100 '/path/to/jdk25-this-pr/bin/java -cp /tmp CCC'
Benchmark 1: /path/to/jdk25-this-pr/bin/java -cp /tmp CCC
  Time (mean ± σ):      51.8 ms ±   2.1 ms    [User: 48.9 ms, System: 16.8 ms]
  Range (min … max):    47.4 ms …  55.1 ms    100 runs

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.

JDK 17: 1.6 s
JDK 21 (no patches): 22 s
JDK25-master: 12.3 s
JDK25-this-pr: 3.1 s

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 on FieldStreamBase.

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8352075: Perf regression accessing fields (Bug - P3)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24713/head:pull/24713
$ git checkout pull/24713

Update a local copy of the PR:
$ git checkout pull/24713
$ git pull https://git.openjdk.org/jdk.git pull/24713/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24713

View PR using the GUI difftool:
$ git pr show -t 24713

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24713.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 17, 2025

👋 Welcome back rvansa! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 17, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 17, 2025
@openjdk
Copy link

openjdk bot commented Apr 17, 2025

@rvansa The following labels will be automatically applied to this pull request:

  • hotspot
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Apr 17, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 17, 2025

Webrevs

@rvansa
Copy link
Author

rvansa commented Apr 24, 2025

Withdrawing in favor of #24847

@rvansa rvansa closed this Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

1 participant