Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exemplar allocations if there are no measurements #5182

Merged
merged 1 commit into from
Feb 12, 2023

Conversation

jack-berg
Copy link
Member

This change is part of the #5178 but can be considered separately.

I noticed that a decent amount of allocations happen in exemplar classes even when exemplars are disabled. The culprit is that we when collecting, we allocate a new ArrayList<>() even when a reservoir has received no measurements.

Performance before:

Benchmark                                                                            (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                                        EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5  3390255558.400 ±  29491981.021   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                         EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           3.007 ±         0.020  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                    EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5    10689731.200 ±     36579.743    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                              EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                               EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                      ms
HistogramCollectBenchmark.recordAndCollect                                        EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  3436534566.600 ± 102736943.608   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                         EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.202 ±         0.199  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                    EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    11536620.800 ±    526953.810    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                              EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                               EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.000                      ms
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9538995141.800 ±  95720490.562   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           0.636 ±         0.030  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6363548.800 ±    305261.174    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5             ≈ 0                  counts
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9042829725.000 ± 169838553.573   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           0.933 ±         0.068  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8849014.400 ±    654075.369    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                    DEFAULT_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                      ms
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  2616061300.000 ±  67260283.355   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.391 ±         0.104  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6559592.000 ±    284720.892    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5             ≈ 0                  counts
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  2624043408.200 ±  48730935.089   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.420 ±         0.167  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     9411476.800 ±    308800.163    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time             ZERO_MAX_SCALE_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                      ms

And after:

Benchmark                                                                                  (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                                              EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5  3375821208.400 ±  30739355.578   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                               EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.799 ±         0.022  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                          EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5     9908505.600 ±     38683.221    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                                    EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                                     EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.000                      ms
HistogramCollectBenchmark.recordAndCollect                                              EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  3414353175.200 ±  24518270.279   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                               EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.061 ±         0.157  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                          EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    10958736.000 ±    509633.147    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                                    EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                                     EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.000                      ms
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9523546925.000 ± 109660916.879   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           0.605 ±         0.032  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6041968.000 ±    367044.332    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5             ≈ 0                  counts
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  9120267599.800 ±  81938280.584   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           0.904 ±         0.069  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8648201.600 ±    709467.779    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count                   DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time                    DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.000                      ms
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  2703226991.600 ± 143524730.218   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.107 ±         0.140  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     5973420.800 ±    300748.546    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5             ≈ 0                  counts
HistogramCollectBenchmark.recordAndCollect                      ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  2569519275.400 ± 130020912.482   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.119 ±         0.125  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8403596.800 ±    301287.233    B/op
HistogramCollectBenchmark.recordAndCollect:·gc.count            ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                  counts
HistogramCollectBenchmark.recordAndCollect:·gc.time             ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           1.000                      ms

A nice improvement, probably on the order of ~10%.

@jack-berg jack-berg requested a review from a team as a code owner February 7, 2023 21:47
@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Base: 91.07% // Head: 91.04% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (b0818b6) compared to base (feb0297).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5182      +/-   ##
============================================
- Coverage     91.07%   91.04%   -0.04%     
+ Complexity     4868     4867       -1     
============================================
  Files           548      548              
  Lines         14373    14379       +6     
  Branches       1378     1378              
============================================
+ Hits          13090    13091       +1     
- Misses          891      893       +2     
- Partials        392      395       +3     
Impacted Files Coverage Δ
.../internal/exemplar/FixedSizeExemplarReservoir.java 89.28% <100.00%> (-1.63%) ⬇️
...y/sdk/metrics/internal/exemplar/ReservoirCell.java 90.47% <0.00%> (-9.53%) ⬇️
...telemetry/sdk/trace/export/BatchSpanProcessor.java 94.48% <0.00%> (-0.69%) ⬇️
...nternal/state/DefaultSynchronousMetricStorage.java 93.10% <0.00%> (+1.72%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

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.

None yet

3 participants