Update LongLastValueAggregator algo to avoid allocations #8017
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: