[SDK] Tracer::StartSpan benchmark and optimizations#4248
Open
dbarker wants to merge 12 commits into
Open
Conversation
…n span start options changed
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4248 +/- ##
==========================================
- Coverage 78.15% 78.15% -0.00%
==========================================
Files 440 440
Lines 18741 18762 +21
==========================================
+ Hits 14645 14661 +16
- Misses 4096 4101 +5
🚀 New features to boost your workflow:
|
…te the NonRecordingSpan. Fix iwyu warnings. Cleanup
dbarker
commented
Jul 15, 2026
|
|
||
| // clang-format off | ||
| // | ||
| // ~/build/sdk/test/trace/tracer_benchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true |
Member
Author
There was a problem hiding this comment.
The optimizations in this PR result in a 11-23% reduction in latency for StartSpan compared to main.
| Benchmark | Baseline (mean ± stddev) | Optimized (mean ± stddev) | Difference % |
|---|---|---|---|
BM_StartSpanTracerDisabled |
6.85 ± 0.025 ns | 5.24 ± 0.046 ns | -23.5% |
BM_StartSpan |
187 ± 1.22 ns | 152 ± 2.74 ns | -18.7% |
BM_StartSpanWithScope |
255 ± 1.09 ns | 218 ± 1.75 ns | -14.5% |
BM_StartSpanWithImplicitParent |
172 ± 0.45 ns | 153 ± 0.80 ns | -11.0% |
BM_StartSpanWithExplicitParentContext |
173 ± 0.34 ns | 154 ± 0.90 ns | -11.0% |
BM_StartSpanWithExplicitRootContext |
187 ± 0.68 ns | 148 ± 0.69 ns | -20.9% |
dbarker
commented
Jul 15, 2026
| // BM_TraceIdRatioBasedSamplerShouldSample_median 4.00 ns 4.00 ns 5 | ||
| // BM_TraceIdRatioBasedSamplerShouldSample_stddev 0.032 ns 0.032 ns 5 | ||
| // BM_TraceIdRatioBasedSamplerShouldSample_cv 0.80 % 0.80 % 5 | ||
| // BM_SpanCreation_mean 205 ns 205 ns 5 |
Member
Author
There was a problem hiding this comment.
Comparison with main and this PR on span sampler benchmark. The NoopSpanCreation case is where the tracer is enabled but the sampler decides to not sample the span (AlwaysOffSampler).
| Benchmark | Baseline (mean ± stddev) | Optimized (mean ± stddev) | Difference % |
|---|---|---|---|
BM_SpanCreation |
235 ± 0.62 ns | 205 ± 1.00 ns | -12.8% |
BM_NoopSpanCreation |
59.3 ± 0.42 ns | 27.7 ± 0.14 ns | -53.3% |
…for more consistent results
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.
Fixes # (issue)
The
Tracer::StartSpanfunction currently performs some unnecessary dynamic memory allocation (allocating a SpanContext and potentially a DefaultSpan) and copying of global static shared pointers by constructing temporary span contexts (which call TraceState::GetDefault()).This latency can be removed without breaking changes. The added benchmark showed a latency reduction of ~11-23% for the range of span creation scenarios (tracer disabled, span with no parent, implicit parent, and explicit parent).
Changes
For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes