-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8331114: Further improve performance of MethodTypeDesc::descriptorString #18945
Conversation
👋 Welcome back redestad! A progress list of the required criteria for merging this PR into |
@cl4es This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
Outdated
Show resolved
Hide resolved
Do we have any research on the average length of method descriptor strings? I wonder if manual pre-allocation works better (iterating all descriptor strings, allocate the sum of their sizes plus 2 (for parentheses), as descriptor strings won't be re-calculated after initial allocation.) |
src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
Outdated
Show resolved
Hide resolved
I don't know of any systematic research on this, but in the code generators we have in the JDK short method signatures outweigh more complex ones by far. So if we can improve for small descriptors without regressing large ones then that's a pretty good win. I've done some micro-benchmarking on longer descriptors and there's still a gain from the proposed patch:
I'd be happy to add a variant that stresses larger descriptors. |
What if we replace int size = 2 + returnType().descriptorString().length();
for (var param : argTypes)
size += param.descriptorString().length(); (Would be even better if we can just trust the internal array to avoid copy allocation) |
Correction: I ran the wrong benchmark for that long descriptor test! 🤦🏽 On the
Since this strays a bit from what's doable in |
src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java
Outdated
Show resolved
Hide resolved
For the precise-length approach, do you have the results? I guess if we can avoid copying the stringbuilder array, we can make this even faster. |
Not sure what you mean - the latest performance numbers I posted are for the precise length version (15c8d39) if that was unclear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am glad that this only focuses on the descriptor string as MethodTypeDesc::displayDescriptor
is typically used for debugging and exception message and not performance-sensitive.
Yes, which is why I'd really like to desugar it: this is the method where I tripped on a bootstrap circularity when print-debugging an issue in the lambda code generator. It's no fun at all hitting bootstrapping issues when calling innocuous methods in Obviously the performance of it is not important - I was just stringing it along for consistency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can update the copyright of this file if you don't mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following up the feedback for 8331187.
Thanks! /integrate |
Going to push as commit a078b5e.
Your commit was automatically rebased without conflicts. |
When analyzing (startup) performance of the Classfile API I found this opportunity to further improve
MethodTypeDescImpl::descriptorString
.Performance improves across the board in existing microbenchmarks:
The improvement is even more pronounced when running with
-Xint
, which is relevant for reducing startup overheads of early ClassFile API use:I also applied similar approach to
MethodTypeDesc::displayDescriptor
: while not performance sensitive I think these are so inter-related that it makes sense to implement them in a similar fashion.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18945/head:pull/18945
$ git checkout pull/18945
Update a local copy of the PR:
$ git checkout pull/18945
$ git pull https://git.openjdk.org/jdk.git pull/18945/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18945
View PR using the GUI difftool:
$ git pr show -t 18945
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18945.diff
Webrev
Link to Webrev Comment