Skip to content

Conversation

@CodeBlanch
Copy link
Member

Changes

  • Followed-up on conversation from the last PR. Moved the histogram sum tracking to HistogramBuckets. That saved 8 bytes for the non-histogram MetricPoints. Also used SnapshotBucketCounts for the histogram lock to save an object allocation.

  • Added missing xml comments in MetricPoint, HistogramBuckets, & HistogramBucket.

  • Added some inlining hints on MetricPoint.

  • Renamed from "current"/"snapshot" to "running"/"snapshot" which seemed closer to what is going on.

Benchmarks

Before

AggType Allocated
LongSumIncomingCumulative 112 B
DoubleSumIncomingCumulative 112 B
Histogram 408 B

After

AggType Allocated
LongSumIncomingCumulative 104 B
DoubleSumIncomingCumulative 104 B
Histogram 384 B

Investigation Notes

What I really wanted to do was this (more or less):

    [StructLayout(LayoutKind.Explicit)]
    internal struct MetricPointSecondaryValueStorage
    {
        [FieldOffset(0)]
        public double DeltaLastValue;

        [FieldOffset(0)]
        public HistogramBuckets HistogramBuckets;
    }

Basically use 8 bytes for either the delta value or the pointer to HistogramBuckets. Actually compiles fine, but blows up trying to load the assembly. Something about you can't overlap a reference object with a value type because it would mess up the GC's ability to track that reference in order to know if it should be cleaned up or not.

@CodeBlanch CodeBlanch requested a review from a team December 2, 2021 05:14
@codecov
Copy link

codecov bot commented Dec 2, 2021

Codecov Report

Merging #2718 (400fec9) into main (4bf8ed4) will decrease coverage by 0.00%.
The diff coverage is 82.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2718      +/-   ##
==========================================
- Coverage   83.77%   83.76%   -0.01%     
==========================================
  Files         251      251              
  Lines        8830     8835       +5     
==========================================
+ Hits         7397     7401       +4     
- Misses       1433     1434       +1     
Impacted Files Coverage Δ
src/OpenTelemetry/Metrics/HistogramBucket.cs 100.00% <ø> (ø)
src/OpenTelemetry/Metrics/Metric.cs 94.44% <ø> (-0.08%) ⬇️
src/OpenTelemetry/Metrics/MetricPoint.cs 85.60% <81.15%> (-0.11%) ⬇️
src/OpenTelemetry/Metrics/HistogramBuckets.cs 100.00% <100.00%> (ø)
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 70.75% <0.00%> (-0.95%) ⬇️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 82.35% <0.00%> (+2.94%) ⬆️

@cijothomas cijothomas mentioned this pull request Dec 8, 2021
3 tasks
@mic-max
Copy link
Contributor

mic-max commented Dec 9, 2021

LGTM 👍

@cijothomas cijothomas merged commit cf3b119 into open-telemetry:main Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants