perf(sdk-trace-base): use counter for attribute limit check in Span#6283
Merged
david-luna merged 3 commits intoopen-telemetry:mainfrom Jan 29, 2026
Merged
Conversation
7e450b7 to
47e451a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6283 +/- ##
=======================================
Coverage 95.68% 95.68%
=======================================
Files 313 313
Lines 9667 9671 +4
Branches 2226 2227 +1
=======================================
+ Hits 9250 9254 +4
Misses 417 417
🚀 New features to boost your workflow:
|
This was referenced Jan 15, 2026
Contributor
|
@AbhiPrasad this PR has some conflicts. Could you please update? Thank you! |
david-luna
approved these changes
Jan 29, 2026
Replace O(n) Object.keys().length call with O(1) counter lookup when checking attribute count limits in setAttribute(). This eliminates O(n²) complexity when adding many attributes to a span. Benchmark results show up to 22x improvement for spans with 128 attributes.
f3654ba to
da51619
Compare
Member
Author
|
I think the unit test failure is a flake |
Contributor
|
Restarted the check. Let see if it goes through |
Merged
via the queue into
open-telemetry:main
with commit Jan 29, 2026
b97b488
36 of 37 checks passed
5 tasks
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?
Replace O(n)
Object.keys().lengthcall with O(1) counter lookup when checking attribute count limits insetAttribute().Benchmark results show up to 22x improvement for spans with 128 attributes (worst case). From my experience at Sentry, most auto-instrumented Node.js spans tend to have ~50-60 attributes, so I'd expect atleast a 5x speedup in the average case.
Short description of the changes
_attributesCountprivate counter field toSpanImplclass to track the number of attributesObject.keys(this.attributes).length(O(n)) withthis._attributesCount(O(1)) in the attribute limit checkType of change
Performance improvement
How Has This Been Tested?
Add a new benchmark for this (AI generated). Tested on a 2021 Apple M1 Pro 32 GB - MacOS 15.5 (24F74)
Checklist: