perf(sdk-trace-base): avoid Object.entries in Span.setAttributes#6514
Merged
dyladan merged 2 commits intoopen-telemetry:mainfrom Mar 23, 2026
Merged
Conversation
c6523a6 to
bc959dd
Compare
This was referenced Mar 21, 2026
dyladan
approved these changes
Mar 21, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6514 +/- ##
=======================================
Coverage 95.75% 95.75%
=======================================
Files 364 364
Lines 12095 12096 +1
Branches 2884 2885 +1
=======================================
+ Hits 11581 11582 +1
Misses 514 514
🚀 New features to boost your workflow:
|
pichlermarc
approved these changes
Mar 23, 2026
Contributor
|
Thank you for your contribution @daniellockyer! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |
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.
Which problem is this PR solving?
Whilst looking at the performance overhead of OTel, I noticed
setAttributesin unusually heavy in comparison tosetAttribute. Turns out, we're using Object.entries for the loop here, which is much heavier than a standard for-in loop. This change has been made several other times in this repo, such as in #5866 and #6287.Part of the flamegraph showing the

setAttributescall has overhead in comparison tosetAttribute:Many instrumentations use
setAttributes, includinghttp, so we should see strong improvements across the board.Before:
After:
You can see span creation with
setAttributesis now on par with the performance of the benchmark using 10xsetAttributethanks to the 22% performance improvement 🚀refs #6100
Short description of the changes
Replace
Object.entrieswith a for-in loop for better performance.Also adds a benchmark test for span creation using
setAttributes.Type of change
Please delete options that are not relevant.
Bug fix (non-breaking change which fixes an issue)New feature (non-breaking change which adds functionality)Breaking change (fix or feature that would cause existing functionality to not work as expected)This change requires a documentation updateHow Has This Been Tested?
Tests still pass, and see benchmark results from above.
Checklist:
Unit tests have been addedDocumentation has been updated