Update LongLastValueAggregator algo to avoid allocations#8017
Merged
jack-berg merged 1 commit intoopen-telemetry:mainfrom Jan 28, 2026
Merged
Update LongLastValueAggregator algo to avoid allocations#8017jack-berg merged 1 commit intoopen-telemetry:mainfrom
jack-berg merged 1 commit intoopen-telemetry:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8017 +/- ##
============================================
+ Coverage 90.16% 90.17% +0.01%
- Complexity 7483 7484 +1
============================================
Files 836 836
Lines 22562 22562
Branches 2237 2237
============================================
+ Hits 20343 20346 +3
+ Misses 1515 1513 -2
+ Partials 704 703 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
zeitlinger
approved these changes
Jan 27, 2026
There was a problem hiding this comment.
Pull request overview
This PR eliminates memory allocations in LongLastValueAggregator by replacing boxed Long objects with primitive long values wrapped in AtomicLong. This optimization mirrors a fix previously applied to DoubleLastValueAggregator in PR #7264.
Changes:
- Replaced
AtomicReference<Long>withAtomicReference<AtomicLong>to avoid boxing allocations - Added
AtomicLong valuefield to hold the actual long value - Updated
doRecordLonganddoAggregateThenMaybeResetLongsto work with the new structure - Reduced memory allocations from ~230KB/op to near-zero in benchmarks
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Looking at the recent #8000, something jumped out at me.. Gauges we're allocating a seemingly large amount of memory!
Note, the benchmarks shown in #8000 description were generated using the benchmark build command
java -jar *-jmh.jar .., which only emits theops/ssummary figure. If you instead run./gradlew :sdk:all:jmh -PjmhIncludeSingleClass=MetricRecordBenchmark, you get a more detailed output which includesB/op.Anyway, all the other metrics have tiny
B/opfigures near zero thanks to our work to reduce allocations. Meanwhile,GAUGE_LAST_VALUEis reporting figures like229945 B/op. This isn't as bad as it looks. Each op is actually10 * 1024distinct record operations, so the actual B/op is229945 / (10 * 1024) = 22 B/op. Much better, but still not good.I tracked it down to very old code in
LongLastValueAggregatordoing Long / long unboxing. Interestingly, we managed to solve this problem forDoubleLastValueAggregatora while back, but the neglected to apply the solution to doubles.Anyway, the fix is straight forward and mirrors the logic of
DoubleLastValueAggregator.Here's the before and after, with allocations approaching zero.
Before:
After: