[OpenTelemetry] Improve HistogramExplicitBounds#7165
Conversation
Apply recommendations from open-telemetry#3428: - Use SIMD vectorization to find buckets. - Use radix sort. - Apply cap to histogram explicit bounds (10M). Written primarily by Copilot through an iterative approach.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7165 +/- ##
==========================================
+ Coverage 89.86% 89.93% +0.06%
==========================================
Files 275 275
Lines 13852 13935 +83
==========================================
+ Hits 12448 12532 +84
+ Misses 1404 1403 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Add missing patch coverage.
Fix CS8604 warning.
Benchmark ResultsCopilot Summary
Runtime trends
Notable improvements
Notable regressions
Caveat on the largest regressionsSome of the biggest percentage regressions come from very small sub-nanosecond baselines in
So the practical picture is:
Detailed ResultsExpand to viewmain
This PR
|
Add note for histogram boundary upper limit.
There was a problem hiding this comment.
Pull request overview
Improves histogram explicit-bound bucket lookup performance in the metrics pipeline, and adds a hard cap on the number of explicit boundaries to prevent pathological allocations/processing.
Changes:
- Replaces the previous large-bound lookup strategy with a radix-partitioned search + SIMD-accelerated linear scan fallback.
- Adds a 10,000,000 max explicit boundary count check for both view configuration and instrument advice.
- Adds unit tests, fuzz/property tests, and benchmarks; updates changelog and solution/project wiring.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Tests/Metrics/MetricViewTests.cs | Adds unit test validating boundary-count limit exception details. |
| test/OpenTelemetry.Tests/Metrics/AggregatorTests.cs | Adds coverage for large-bound lookup edge cases (mixed signs, infinities, NaN, degenerate NaN bounds) and display-bounds cleanup. |
| test/OpenTelemetry.FuzzTests/OpenTelemetry.FuzzTests.csproj | New fuzz test project for OpenTelemetry core metrics. |
| test/OpenTelemetry.FuzzTests/Metrics/HistogramExplicitBoundsFuzzTests.cs | Adds FsCheck property tests comparing optimized path vs scalar baseline. |
| test/Benchmarks/Metrics/HistogramExplicitBoundsBenchmarks.cs | Adds BenchmarkDotNet benchmarks for bucket lookup across sizes/layouts. |
| src/OpenTelemetry/OpenTelemetry.csproj | Grants InternalsVisibleTo for the new OpenTelemetry.FuzzTests project. |
| src/OpenTelemetry/Metrics/View/ExplicitBucketHistogramConfiguration.cs | Introduces MaxBoundaryCount and enforces it when setting Boundaries. |
| src/OpenTelemetry/Metrics/MetricStreamIdentity.cs | Enforces MaxBoundaryCount for instrument advice-provided boundaries. |
| src/OpenTelemetry/Metrics/HistogramExplicitBounds.cs | Implements radix-partitioned + SIMD-assisted bucket index lookup and infinity cleanup. |
| src/OpenTelemetry/CHANGELOG.md | Documents the explicit-boundary cap as a breaking change. |
| OpenTelemetry.slnx | Adds the new fuzz test project to the solution. |
Comments suppressed due to low confidence (1)
src/OpenTelemetry/Metrics/View/ExplicitBucketHistogramConfiguration.cs:74
IsSortedAndDistinctcurrently treatsdouble.NaNas valid because all comparisons with NaN return false, so arrays containing NaN can pass validation even though they are not meaningfully “ascending order with distinct values”. Consider explicitly rejecting NaN (and possibly non-finite values) in this check soBoundariesvalidation matches the documented requirements and downstream bucketing assumptions.
for (var i = 1; i < values.Length; i++)
{
if (values[i] <= values[i - 1])
{
return false;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix incorrect ArgumentException parameter name.
|
@cijothomas, could you please check this PR? Especially adding boundaries? |
Fixes #3428
Changes
Apply recommendations from #3428:
Written primarily by Copilot through an iterative approach.
Final benchmark results are shown below: #7165 (comment)
I haven't benchmarked the ARM64 SIMD branch as I don't have the hardware for that locally.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)