-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Optimization for StringBuilder append boolean and null #15990
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
Conversation
|
👋 Welcome back wenshao! A progress list of the required criteria for merging this PR into |
This comment was marked as resolved.
This comment was marked as resolved.
|
@cl4es could you please review my code? Thank you! |
|
Are these common enough that 2-3ns/op is a real win on any real app? Instead of obfuscating core library code with |
src/java.base/share/classes/java/lang/AbstractStringBuilder.java
Outdated
Show resolved
Hide resolved
Co-authored-by: ExE Boss <[email protected]>
I think StringBuilder.append(boolean/null) are common operations, and now we know that using ByteArrayLittleEndian can improve performance. Does JIT have any plans to do such optimization? |
|
Can you try replacing the individual char puts with |
The implementation using append(b ? "true" : "false") will be slower than the baseline version public AbstractStringBuilder append(boolean b) {
if (isLatin1()) {
return append(b ? "true" : "false");
}
...
} |
|
@wenshao This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@wenshao This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
|
/open |
|
@wenshao This pull request is now open |
|
We now have a PR for merging stores efficiently: #16245 It would be good to run the microbenchmarks you have evaluated here on that PR branch and see if that optimization narrows the gap. I have some hope we'll be able to dial back the use of |
|
PR #16245 performs better
|
|
@wenshao This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
| */ | ||
| abstract sealed class AbstractStringBuilder implements Appendable, CharSequence | ||
| permits StringBuilder, StringBuffer { | ||
|
|
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.
Redundant line.
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 extra line existed before this PR
|
The current implementation will have performance degradation when the coder is UTF16, but if combined with PR #16245, it will have very good performance. The performance numbers under MacBookPro M1 Max are as follows: |
|
❗ This change is not yet ready to be integrated. |
|
@wenshao This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@wenshao This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
Improve the performance of StringBuilder's append(boolean) and append(null).
When the coder is latin1, treat null/fals/true as an int. If the coder is utf16, treat it as a long, use ByteArrayLittleEndian.setInt/setLong to write it into buf.
The performance numbers under MacBookPro M1 Max are as follows:
Please review and don't hesitate to critique my approach and patch.
Progress
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15990/head:pull/15990$ git checkout pull/15990Update a local copy of the PR:
$ git checkout pull/15990$ git pull https://git.openjdk.org/jdk.git pull/15990/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15990View PR using the GUI difftool:
$ git pr show -t 15990Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15990.diff