opentelemetry-sdk: remove copy on span instantiation#5272
Merged
Conversation
This copy isn't necessary as the init method of the BoundedAttributes (inside the span's init method) already iterates through and copies all the attributes in a new Dict. Ran some benchmarks before and after the change with: ``` pytest opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py::test_start_span_with_attributes \ --memray --trace-python-allocators --benchmark-disable -v ``` The following table shows the before and after change savings: | attrs | Before (KiB) | After (KiB) | Saved (KiB) | |------:|-------------:|------------:|------------:| | 0 | 7.5 | 7.3 | 0.2 | | 1 | 8.3 | 8.1 | 0.2 | | 10 | 11.3 | 11.3 | 0.0 | | 50 | 15.8 | 14.3 | 1.5 | | 128 | 28.0 | 24.8 | 3.2 | Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
tammy-baylis-swi
approved these changes
Jun 4, 2026
tammy-baylis-swi
left a comment
Contributor
There was a problem hiding this comment.
Nice! Thank you
MikeGoldsmith
approved these changes
Jun 4, 2026
herin049
approved these changes
Jun 4, 2026
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.
Description
The copy isn't necessary as the init method of the BoundedAttributes (inside the span's init method) already iterates through and copies all the attributes in a new Dict.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Ran some benchmarks before and after the change with:
The following table shows the before and after change savings:
Does This PR Require a Contrib Repo Change?
Checklist: