internal/shared/semconv: Reduce allocations#8511
internal/shared/semconv: Reduce allocations#8511pellared merged 18 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8511 +/- ##
=====================================
Coverage 82.2% 82.2%
=====================================
Files 179 179
Lines 13700 13724 +24
=====================================
+ Hits 11265 11289 +24
Misses 2033 2033
Partials 402 402
🚀 New features to boost your workflow:
|
|
We have removed the duplicate metrics. So I think we could remove even more allocations by removing the |
Great. I didn’t initially make that change because it broke the function signature, but this option is, of course, much more preferable. |
|
We can change internal module's method signature, as long as we don't change the public ones. |
Co-authored-by: Damien Mathieu <42@dmathieu.com>
|
Could you add some before-and-after performance comparison data? We can use benchstat to provide it. |
|
If we compare the variants where the slice is allocated only once, then each call results in exactly one fewer allocation. I decided not to account for removing the map wrapper in the benchmark, I think that part is fairly obvious: func (n HTTPClient) RecordMetricsOld(ctx context.Context, md MetricData, opts MetricOpts) {
n.requestBodySize.Inst().Record(ctx, md.RequestSize, opts.MeasurementOption())
n.requestDuration.Inst().Record(ctx, md.ElapsedTime/1000, opts.MeasurementOption())
}
func (n HTTPClient) RecordMetricsNew(ctx context.Context, md MetricData, opts MetricOpts) {
o := []metric.RecordOption{opts.MeasurementOption()}
n.requestBodySize.Inst().Record(ctx, md.RequestSize, o...)
n.requestDuration.Inst().Record(ctx, md.ElapsedTime, o...)
}Here are the results: |
flc1125
left a comment
There was a problem hiding this comment.
In addition, please fix the CI. We can check it locally by running make ci.
|
Can you please add results from |
Uh oh!
There was an error while loading. Please reload this page.