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

Optimize DefaultSynchronousMetricStorage iteration #5183

Merged
merged 3 commits into from
Feb 22, 2023

Conversation

jack-berg
Copy link
Member

@jack-berg jack-berg commented Feb 7, 2023

Reduces memory allocation required to create Map.Entry instances, as discussed in this comment.

Performance before:

Benchmark                                                                                  (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                                              EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5  3520507291.800 ± 120427365.649   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                               EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.612 ±         0.099  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                          EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5     9642284.800 ±     38984.668    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  3587937850.200 ±  44279700.645   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                               EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.789 ±         0.146  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                          EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    10495027.200 ±    508130.695    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           1.000                      ms
HistogramCollectBenchmark.recordAndCollect                             DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9513074758.000 ± 595008484.127   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           0.608 ±         0.039  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6060252.800 ±     37585.400    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  9063879408.400 ± 194774415.736   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           0.897 ±         0.089  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8527204.800 ±    992718.242    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  2609093750.200 ±  27543850.838   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.214 ±         0.024  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     6057052.800 ±     37585.400    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  2584224741.400 ±  66418902.656   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           3.186 ±         0.109  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8633201.600 ±    167908.737    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

Performance after:

Benchmark                                                                                  (aggregationGenerator)  (aggregationTemporality)  Mode  Cnt           Score           Error   Units
HistogramCollectBenchmark.recordAndCollect                                              EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5  3441942233.200 ±  51767762.295   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                               EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5           2.501 ±         0.040  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                          EXPLICIT_BUCKET_HISTOGRAM                     DELTA    ss    5     9028427.200 ±     38913.294    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           1.000                      ms
HistogramCollectBenchmark.recordAndCollect                                              EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5  3421486925.000 ±  39018402.054   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate                               EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.890 ±         0.150  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm                          EXPLICIT_BUCKET_HISTOGRAM                CUMULATIVE    ss    5    10370520.000 ±    512775.586    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_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5  9561402975.000 ±  76641347.782   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           0.569 ±         0.002  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     5709852.800 ±     37585.400    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  9243150125.200 ± 859901460.104   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate              DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           0.857 ±         0.165  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm         DEFAULT_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8295180.800 ±    980548.020    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  2599680183.400 ±  50496977.640   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5           2.136 ±         0.031  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                     DELTA    ss    5     5824601.600 ±     37081.984    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  2575599391.600 ±  37592514.813   ns/op
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate       ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5           2.983 ±         0.047  MB/sec
HistogramCollectBenchmark.recordAndCollect:·gc.alloc.rate.norm  ZERO_MAX_SCALE_BASE2_EXPONENTIAL_BUCKET_HISTOGRAM                CUMULATIVE    ss    5     8058284.800 ±    158376.473    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

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

codecov bot commented Feb 7, 2023

Codecov Report

Base: 91.08% // Head: 91.09% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (6b9427b) compared to base (c07642e).
Patch coverage: 87.50% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5183   +/-   ##
=========================================
  Coverage     91.08%   91.09%           
- Complexity     4874     4876    +2     
=========================================
  Files           549      549           
  Lines         14418    14420    +2     
  Branches       1372     1371    -1     
=========================================
+ Hits          13133    13136    +3     
+ Misses          891      890    -1     
  Partials        394      394           
Impacted Files Coverage Δ
...nternal/state/DefaultSynchronousMetricStorage.java 92.98% <87.50%> (+1.60%) ⬆️
...nfigure/AutoConfiguredOpenTelemetrySdkBuilder.java 96.29% <0.00%> (+0.02%) ⬆️
.../internal/exemplar/HistogramExemplarReservoir.java 90.90% <0.00%> (+2.02%) ⬆️

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.

@@ -131,12 +131,14 @@ public MetricData collect(

// Grab aggregated points.
List<T> points = new ArrayList<>(aggregatorHandles.size());
for (Map.Entry<Attributes, AggregatorHandle<T, U>> entry : aggregatorHandles.entrySet()) {
T point = entry.getValue().aggregateThenMaybeReset(start, epochNanos, entry.getKey(), reset);
for (Attributes attributes :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion. This reads better and yields the same reduction in allocations.

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

4 participants