perf(sdk): store InstrumentationScope in Arc to avoid clone per processor#3378
Open
bryantbiggs wants to merge 4 commits intoopen-telemetry:mainfrom
Open
perf(sdk): store InstrumentationScope in Arc to avoid clone per processor#3378bryantbiggs wants to merge 4 commits intoopen-telemetry:mainfrom
bryantbiggs wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
…ssor SdkTracer now wraps InstrumentationScope in Arc internally, which makes tracer cloning significantly cheaper (pointer bump instead of deep clone with attribute Vec allocation). The multi-processor span export path is also optimized: instead of calling build_export_data() per processor (which clones the scope from the tracer each time), SpanData is now built once and cloned for each additional processor. The last processor receives the original without a clone. This is a non-breaking change — SpanData's public instrumentation_scope field remains InstrumentationScope (not Arc). Supersedes open-telemetry#3267, thanks to @taisho6339 for the original approach.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3378 +/- ##
=====================================
Coverage 82.2% 82.3%
=====================================
Files 128 128
Lines 24626 24648 +22
=====================================
+ Hits 20267 20296 +29
+ Misses 4359 4352 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Verifies that when multiple span processors are configured, all processors receive the span data with correct name and attributes.
Use split_last() instead of index tracking for the multi-processor on_end loop. Removes unnecessary break statement and makes the clone-for-rest, move-for-last intent explicit. Fix changelog entry to describe what actually changed without overstating the scope clone savings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes to reduce allocation in the tracing pipeline:
SdkTracernow stores itsInstrumentationScopeinArc. Since tracers are cloned on every span creation (build_recording_spancallsself.clone()), this turns the scope copy from a deep clone (allocates a newVec<KeyValue>for attributes) into an Arc refcount increment.The multi-processor
on_endpath now callsbuild_export_data()once and clones the result for additional processors, instead of rebuilding export data from scratch per processor. The last processor receives the original via move. Note: the per-processor clone cost is similar either way — this avoids the redundant rebuild, not the clone itself.This is a non-breaking change.
SpanData.instrumentation_scoperemainsInstrumentationScope, notArc. Theinstrumentation_scope()accessor still returns&InstrumentationScopeviaDeref.Supersedes #3267 — thanks to @taisho6339 for the original approach and discussion.
Relates to #3368.
Changes
SdkTracer.scope:InstrumentationScope→Arc<InstrumentationScope>(internal field, not public API)on_end: build once, clone for rest, move for last