Skip to content

Conversation

@dashpole
Copy link
Contributor

@dashpole dashpole commented Dec 12, 2025

Part of #7535

We currently prepend or append new elements to the counts slice when we get an observation outside of the current buckets. This can't be done in a lockless way.

This PR refactors the expo buckets to instead use a fixed-size pre-allocated slice, and separately track the start and end of the actual slice. For bin i, the getIdx function always returns the same value, so shifting elements within the slice is never required. The only time we will need exclusive access is if we need to downscale.

The downside is that we always allocate the full maxSize number of buckets for positive and negative, even if there are no negative observations. We might be able to lazily initialize the buckets to fix this as a follow-up.

Not much of a performance impact:

                                                                                  │  main.txt   │           circular.txt            │
                                                                                  │   sec/op    │   sec/op     vs base              │
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/0-24      295.9n ± 4%   298.8n ± 4%       ~ (p=0.394 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/1-24      310.4n ± 3%   315.6n ± 5%       ~ (p=0.093 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialInt64Histogram/Attributes/10-24     308.6n ± 6%   303.6n ± 5%       ~ (p=0.485 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/0-24    293.7n ± 7%   305.2n ± 2%  +3.93% (p=0.004 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/1-24    310.9n ± 3%   313.3n ± 3%       ~ (p=0.589 n=6)
SyncMeasure/NoView/ExemplarsDisabled/ExponentialFloat64Histogram/Attributes/10-24   306.9n ± 3%   315.2n ± 5%       ~ (p=0.145 n=6)
geomean                                                                             304.3n        308.5n       +1.39%

The alternative is that we need to lock whenever we resize the bucket array instead of only when we need to downscale.

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.2%. Comparing base (85ec5e4) to head (ff52fba).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #7706     +/-   ##
=======================================
- Coverage   86.2%   86.2%   -0.1%     
=======================================
  Files        302     302             
  Lines      21991   21979     -12     
=======================================
- Hits       18968   18953     -15     
- Misses      2642    2645      +3     
  Partials     381     381             
Files with missing lines Coverage Δ
...metric/internal/aggregate/exponential_histogram.go 97.2% <100.0%> (-0.2%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dashpole dashpole added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant