Skip to content

Don't allocate for parentContext on span start for the common case#8332

Merged
jack-berg merged 1 commit into
open-telemetry:mainfrom
jack-berg:span-start-allocations
Apr 28, 2026
Merged

Don't allocate for parentContext on span start for the common case#8332
jack-berg merged 1 commit into
open-telemetry:mainfrom
jack-berg:span-start-allocations

Conversation

@jack-berg
Copy link
Copy Markdown
Member

#8263 fixed a bug where parentContext wasn't properly being passed to shouldSample for the root case. Its correct, but the code calls parentContext.with(RANDOM_TRACE_ID_PRIMORDIAL_SPAN), which allocates to store the RANDOM_TRACE_ID_PRIMORDIAL_SPAN in context every time a root span is started.

But its common (I would say the majority of the time) for parent context to be Context.root() in this case. Therefore, we can avoid allocating by keeping a constant Context.root().with(RANDOM_TRACE_ID_PRIMORDIAL_SPAN) and always returning that when parentContext == Context.root().

Followup to #8263 (comment)

cc @PeterF778

@jack-berg jack-berg requested a review from a team as a code owner April 24, 2026 19:32
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.25%. Comparing base (fdb8194) to head (7afdc6e).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8332      +/-   ##
============================================
- Coverage     90.27%   90.25%   -0.03%     
  Complexity     7693     7693              
============================================
  Files           850      850              
  Lines         23207    23210       +3     
  Branches       2356     2357       +1     
============================================
- Hits          20951    20948       -3     
- Misses         1530     1537       +7     
+ Partials        726      725       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jack-berg jack-berg merged commit 74964c6 into open-telemetry:main Apr 28, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants