- Notifications
You must be signed in to change notification settings - Fork 327
remove useless allocation in TraceState.copyOf() #1508
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
remove useless allocation in TraceState.copyOf() #1508
Conversation
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.
Leaking a member of a pooled object to another pooled object is very problematic.
I think we should avoid adding the header field to the tracestate list (in TraceState#set()) and adjust the TraceState#toTextHeader() method (as well as the TraceState.TextTracestateAppender#join() method) to append it only when required.
TraceState#copyFrom() already takes care of copying the header value.
This probably means we should change tracestate to be a list of Strings, as opposed to what I previously suggested...
One additional thing to fix is resetting header in TraceState#resetState.
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java Show resolved Hide resolved
…racestate-extra-allocation
Codecov Report
@@ Coverage Diff @@ ## master #1508 +/- ## ============================================ - Coverage 58.96% 58.96% -0.01% Complexity 92 92 ============================================ Files 392 392 Lines 17638 17632 -6 Branches 2447 2446 -1 ============================================ - Hits 10401 10397 -4 + Misses 6520 6517 -3 - Partials 717 718 +1
Continue to review full report at Codecov.
|
eyalkoren left a comment
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.
LGTM.
Few minor comment.
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ConstantSampler.java Outdated Show resolved Hide resolved
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ProbabilitySampler.java Outdated Show resolved Hide resolved
| double getSampleRate(); | ||
| | ||
| // While header is not related to sampler itself, putting this here allows to reuse the same | ||
| // String instance as long as the sample rate does not change to minimize allocation |
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.
👍 Can be added to the javadoc
…racestate-extra-allocation
What does this PR do?
Fixes #1503
Checklist
I have added tests that would fail without this fixtested locally with async-profiler