-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Reduce newEvictedQueueLink
and newEvictedQueueEvent
memory allocations
#5858
Reduce newEvictedQueueLink
and newEvictedQueueEvent
memory allocations
#5858
Conversation
benchstat: ``` goos: linux goarch: amd64 pkg: go.opentelemetry.io/otel/sdk/trace cpu: 11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ TraceStart/with_a_simple_span-12 743.6n ± 5% 451.0n ± 5% -39.36% (p=0.000 n=10) TraceStart/with_several_links-12 944.4n ± 7% 595.8n ± 3% -36.91% (p=0.000 n=10) TraceStart/with_attributes-12 1034.5n ± 7% 644.5n ± 10% -37.70% (p=0.000 n=10) geomean 898.9n 557.4n -38.00% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ TraceStart/with_a_simple_span-12 704.0 ± 0% 496.0 ± 0% -29.55% (p=0.000 n=10) TraceStart/with_several_links-12 880.0 ± 0% 672.0 ± 0% -23.64% (p=0.000 n=10) TraceStart/with_attributes-12 960.0 ± 0% 752.0 ± 0% -21.67% (p=0.000 n=10) geomean 841.0 630.5 -25.03% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ TraceStart/with_a_simple_span-12 14.000 ± 0% 2.000 ± 0% -85.71% (p=0.000 n=10) TraceStart/with_several_links-12 15.000 ± 0% 3.000 ± 0% -80.00% (p=0.000 n=10) TraceStart/with_attributes-12 16.000 ± 0% 4.000 ± 0% -75.00% (p=0.000 n=10) geomean 14.98 2.884 -80.74% ```
newEvictedQueueLink
and newEvictedQueueEvent
memory allocations
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5858 +/- ##
=======================================
- Coverage 84.5% 84.5% -0.1%
=======================================
Files 272 272
Lines 22800 22804 +4
=======================================
+ Hits 19283 19284 +1
- Misses 3171 3174 +3
Partials 346 346 |
8ed5a03
to
f14cd66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Left a small changelog comment.
Co-authored-by: Damien Mathieu <42@dmathieu.com>
Hey @dmathieu |
…OverCapAttrs` (#5864) Good day, While working on #5858 I found some other possible improvements. This PR: - Adds an early return to `SetAttributes` when no attributes are provided. - Only increases `s.attributes` to guarantee that there is enough space for elements to be added. - Fixes and issue where `truncateAttr` was not used when a attribute was being updated in `addOverCapAttrs`. Thanks for reviewing and please let me know if any changes are needed. --------- Co-authored-by: Damien Mathieu <42@dmathieu.com>
### Added - Add `go.opentelemetry.io/otel/sdk/metric/exemplar` package which includes `Exemplar`, `Filter`, `TraceBasedFilter`, `AlwaysOnFilter`, `HistogramReservoir`, `FixedSizeReservoir`, `Reservoir`, `Value` and `ValueType` types. These will be used for configuring the exemplar reservoir for the metrics sdk. (#5747, #5862) - Add `WithExportBufferSize` option to log batch processor.(#5877) ### Changed - Enable exemplars by default in `go.opentelemetry.io/otel/sdk/metric`. Exemplars can be disabled by setting `OTEL_METRICS_EXEMPLAR_FILTER=always_off` (#5778) - `Logger.Enabled` in `go.opentelemetry.io/otel/log` now accepts a newly introduced `EnabledParameters` type instead of `Record`. (#5791) - `FilterProcessor.Enabled` in `go.opentelemetry.io/otel/sdk/log/internal/x` now accepts `EnabledParameters` instead of `Record`. (#5791) - The `Record` type in `go.opentelemetry.io/otel/log` is no longer comparable. (#5847) - Performance improvements for the trace SDK `SetAttributes` method in `Span`. (#5864) - Reduce memory allocations for the `Event` and `Link` lists in `Span`. (#5858) - Performance improvements for the trace SDK `AddEvent`, `AddLink`, `RecordError` and `End` methods in `Span`. (#5874) ### Deprecated - Deprecate all examples under `go.opentelemetry.io/otel/example` as they are moved to [Contrib repository](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/examples). (#5854) ### Fixed - The race condition for multiple `FixedSize` exemplar reservoirs identified in #5814 is resolved. (#5819) - Fix log records duplication in case of heterogeneous resource attributes by correctly mapping each log record to it's resource and scope. (#5803) - Fix timer channel drain to avoid hanging on Go 1.23. (#5868) - Fix delegation for global meter providers, and panic when calling otel.SetMeterProvider. (#5827) - Change the `reflect.TypeOf` to use a nil pointer to not allocate on the heap unless necessary. (#5827)
Good day,
While doing some profile with pprof on one of our services I notices that
sync.OnceFunc
was allocating a nice amount of objects. Thesesync.OnceFunc
calls where done bynewEvictedQueueEvent
andnewEvictedQueueLink
.So to avoid these extra allocation I created this PR which replaces the
sync.OnceFunc
withsync.Once
which is now part of the evictedQueue.This resulted in the following benchstat result (commit baad07e):