HDDS-16280. Avoid eager Preconditions message on hot paths - #11131
Open
NickJavaDev88 wants to merge 2 commits into
Open
HDDS-16280. Avoid eager Preconditions message on hot paths#11131NickJavaDev88 wants to merge 2 commits into
NickJavaDev88 wants to merge 2 commits into
Conversation
Contributor
Author
|
Hi @rich7420, thanks for reporting this issue in Jira! Could you please take a look when you have a chance? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Guava's
Preconditions.checkState(boolean, String)evaluates its message argument before the call, so the error string is built viaStringBuilderconcatenation on every invocation even when the check passes. Two of these sit on hot paths:XceiverClientRatis.watchForCommitruns the check on every commit-watch reply ("Returned index " + updated + " < expected " + index).ReferenceCounted.decrementRefCountruns it on every snapshot reference release ("This thread " + tid + " already have a reference count of zero.").Each successful check allocates a
StringBuilder, its backingchar[]and the resultingString, all short-lived garbage that only adds young-gen GC pressure.This PR switches both call sites to Guava's template form (
checkState(condition, "... %s ... %s", arg1, arg2)). Guava resolves these to its primitivelongoverloads (checkState(boolean, String, long, long)andcheckState(boolean, String, long)), so no boxing orObject[]allocation occurs, and the message is only formatted when the check fails. The failure messages are unchanged.This is a sub-task of HDDS-16276.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16280
How was this patch tested?
No functional change, so no new tests were added:
longvariants is compiler-verified (confirmed against Guava 33.6.0 sources; JLS most-specific applicable method).Verified locally:
mvn compile -pl :hdds-client,:ozone-manager -am -DskipShade -DskipRecon -DskipDocs-> BUILD SUCCESS./hadoop-ozone/dev-support/checks/checkstyle.sh-> 0 violationsA standalone JMH benchmark (not part of this PR — Ozone has no JMH harness) confirms
the allocation saved on the passing path (check always true), JDK 21.0.7,
-prof gc:eageris the current"..." + a + " ... " + bform;lazyis the"... %s ... %s", a, btemplate form, which Guava resolves to
checkState(boolean, String, long, long)— no boxing,no
Object[], message built only on failure. 240 B/op of throwaway garbage per passing checkbecomes zero.
CI on the fork: https://github.com/NickJavaDev88/ozone/actions/runs/33087782394