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
8303078: Reduce allocations when pretty printing JCTree during compilation #12667
8303078: Reduce allocations when pretty printing JCTree during compilation #12667
Conversation
👋 Welcome back dreis2211! A progress list of the required criteria for merging this PR into |
@dreis2211 The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
In terms of some more absolute allocation numbers: Before (TOP 3 => ~5,6GB)
After (TOP 3 => ~5,4GB)
|
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.
If we proceed with this, I would recommend looking for other possible uses of the new method.
A simple grep
shows 129 single character strings, of which 97 are arguments to print
.
Separate but related, I note that a similar class, DocPretty.java
, has 75 single character strings, of which 68 are arguments to print.
Overall changing the coding style to use out.print(char)
seems worthwhile.
@jonathan-gibbons Thanks for your review.
That's the idea - there are multiple cases where this could be used. I'll push an updated version that already changes things to make reviewing a bit easier. EDIT: Done. |
Filed JDK-8303078 You might want to un-Draft the PR, and prefix the title with |
There are 19 instances of string concatenation in |
c4a003c
to
846c8eb
Compare
846c8eb
to
3efe9d5
Compare
@jonathan-gibbons Made the adjustments to |
3efe9d5
to
45d1219
Compare
@dreis2211 Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
Webrevs
|
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.
this is looking good, I think that once the changes to DocPretty.java
, as Jon suggested, are included in this patch it should be good to go
@vicente-romero-oracle & @jonathan-gibbons made the adjustments to |
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java
Outdated
Show resolved
Hide resolved
src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocPretty.java
Outdated
Show resolved
Hide resolved
There are some test failures in langtools/tier1 that seem related. Will check |
I confirm that all the langtools tests now pass, at least on my local laptop. |
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 updating DocPretty.java
to follow the same conventions as Pretty.java
, even though it was probably not required for your Lombok-based use-case.
I've gone through all the latest patch, and run all the langtools tests as well. All pass on my laptop, and there is no reason to expect any cross-platform issues.
I'll mark it Approved, but while not strictly necessary, I recommend that you wait for Vicente's approval as well, in case he has any final comments.
@dreis2211 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 66 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@jonathan-gibbons, @vicente-romero-oracle) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
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.
looks good. I will run an internal test that executes all regression tests in all supported platforms just to be xtra sure
all green :) |
/integrate |
@dreis2211 |
Mailing list message from Jonathan Gibbons on compiler-dev: Regarding paranoia: I'll address that in the PR, I'd like to record the Regarding the scary comment: the comment goes back to pre-module days, -- Jon On 2/22/23 11:02 AM, Christoph Dreis wrote: |
/sponsor |
Going to push as commit 58ca711.
Your commit was automatically rebased without conflicts. |
@jonathan-gibbons @dreis2211 Pushed as commit 58ca711. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Thanks @jonathan-gibbons & @vicente-romero-oracle for your active advice, reviewing and sponsoring :) |
You're welcome; thanks for the contribution. |
+1 |
Hi,
I've been recently optimizing a few project pipelines and always noticed that their compilation step is somewhat "expensive". Zooming into the issue always revealed Lombok to be a larger contributor. Unfortunately, I can't get rid of Lombok in this customer project (before you ask).
Apparently, Lombok is printing the respective

JCTree
here and there to check for type matches. I can't imagine this to be super efficient, but that's how it is at the moment.Anyhow, regardless of the Lombok inefficiencies I think there are some optimization opportunities in the JDK itself.
Pretty.visitSelect
accounts for 8-10% of the total allocations in this project. And among those there are StringBuilder allocations coming from the following:This PR splits the
print
calls into two separate ones to avoid this String concatenation.Secondly, the
, or any braces like
print
method takes anObject
which seems like a good fit for another (private?) variant of it that only takes achar
. By this we would probably avoid any eventual boxing and avoid any conversion withConvert.escapeUnicode(s.toString())
that seems superfluous for chars like.
,(
,{
etc.This is currently a draft PR as long as the scope is not clarified. It currently only includes the necessary changes that would optimize the particular use-case. But there are more cases where e.g. the new
char
variant could be used and/or any String concatenation could be split into separateprint
calls.Let me know what you think and if I should include the other cases as well. If you think this is worthwhile, I'd appreciate if this is is sponsored. (Including creating an issue as I can't do this myself apparently. I will of course squash everything together with the proper issue ID once available.)
I've contributed before, so the CLA should be signed.
Cheers,
Christoph
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/12667/head:pull/12667
$ git checkout pull/12667
Update a local copy of the PR:
$ git checkout pull/12667
$ git pull https://git.openjdk.org/jdk pull/12667/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12667
View PR using the GUI difftool:
$ git pr show -t 12667
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12667.diff