perf(sdk-trace-base): optimize TraceIdRatioBasedSampler hex parsing#6284
Open
AbhiPrasad wants to merge 2 commits intoopen-telemetry:mainfrom
Open
perf(sdk-trace-base): optimize TraceIdRatioBasedSampler hex parsing#6284AbhiPrasad wants to merge 2 commits intoopen-telemetry:mainfrom
AbhiPrasad wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6284 +/- ##
=======================================
Coverage 95.68% 95.68%
=======================================
Files 313 313
Lines 9667 9670 +3
Branches 2226 2227 +1
=======================================
+ Hits 9250 9253 +3
Misses 417 417
🚀 New features to boost your workflow:
|
Contributor
|
This is missing a changelog entry. |
Member
Author
|
forgot the git push! |
Contributor
|
@AbhiPrasad there are some conflicts. Please fix them so we can move on this PR :) |
Optimize the `_accumulate` method in TraceIdRatioBasedSampler by replacing `parseInt()` with string slicing with direct `charCodeAt()` hex parsing. This avoids creating temporary strings via `slice()` and the overhead of `parseInt()` for each of the 4 chunks of the trace ID. | Version | ops/sec | Improvement | |---------|---------|-------------| | Original (parseInt + slice) | 2,742,516 | baseline | | Optimized (charCodeAt) | 3,152,165 | +15% | The optimization preserves exact behavioral compatibility - the same trace IDs will produce the same sampling decisions as before. Also adds a benchmark for the sampler to track performance.
c4141b6 to
c70e05a
Compare
Member
Author
|
Rebased this branch and fixed the conflicts |
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?
Optimize the
_accumulatemethod in TraceIdRatioBasedSampler by replacingparseInt()with string slicing with directcharCodeAt()hex parsing. This avoids creating temporary strings viaslice()and the overhead ofparseInt()for each of the 4 chunks of the trace ID. Improves sampling decision calls by 15%.The optimization preserves exact behavioral compatibility - the same trace IDs will produce the same sampling decisions as before.
Type 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: