feat(ddtrace/tracer): add span lifecycle benchmarks#4682
feat(ddtrace/tracer): add span lifecycle benchmarks#4682
Conversation
b627ddf to
a2cb245
Compare
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: a2cb245 | Docs | Datadog PR Page | Give us feedback! |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2cb24562b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| b.Setenv("DD_GIT_REPOSITORY_URL", "https://github.com/DataDog/dd-trace-go") | ||
| b.Setenv("DD_GIT_COMMIT_SHA", "abc123def456789abc123def456789abc123def4") |
There was a problem hiding this comment.
Refresh git metadata after setting benchmark env
When this benchmark is run in the normal go test -bench flow, package tests such as TestGitMetadata can leave the internal git metadata cache already initialized/refreshed under different env values; GetGitMetadataTags is cached and these later Setenv calls are not observed unless internal.RefreshGitMetadataTags() is called. In that scenario the benchmark silently runs with stale or empty _dd.git.* tags, so it does not actually exercise the git-metadata hot path it is intended to measure.
Useful? React with 👍 / 👎.
BenchmarksBenchmark execution time: 2026-04-20 19:17:28 Comparing candidate commit a2cb245 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 156 metrics, 8 unstable metrics.
|
What does this PR do?
Adds
BenchmarkSpanLifecycle— an end-to-end benchmark for the span hot path (start → sample → tag → finish) with settings that exercise all 6 optimization PRs merged across v2.6–v2.8:setTagLockedfromSetTagfor use during span construction #4425 —setTags()batch lock (avoid per-tag lock inStartSpan)prioritySampler.getRate#4423 —serviceEnvKeystruct map key (avoid string concat inprioritySampler.getRate)SamplerName.DecisionMaker()lookup table (avoidstrconv.Itoa)_dd.p.dmnumeric value at write-time #4576 —_dd.p.dmpre-compute at write time (avoidstrconv.ParseIntper flush)updateTracerGitMetadataTagsfixed arrays (avoid map alloc per root span)traceIDhex encoding caching (avoid repeated hex encode)Three sub-benchmarks focus on root spans where all 6 optimizations converge (child spans inherit sampling priority and skip 4 of 6 paths):
Tag()options, baseline signal.setTagsbatch lock improvement.serviceEnvKeymap lookups with different keys.Motivation
No existing benchmark exercised the full span lifecycle with sampling enabled, global tags, git metadata, and 128-bit trace IDs — the conditions needed to measure these optimizations together. Existing benchmarks either disable sampling (
WithSamplerRate(0)) or measure isolated components.Results (v2.5.0 → v2.8.0, 10 runs, Apple M1 Max)
The 6 PRs delivered ~3% fewer bytes and ~5% fewer allocs. CPU regressed ~3-8% due to the
internalConfigrefactor (#4645, #4559, #4653) which replaced direct field reads with RLock/defer/RUnlock accessor methods (~8 mutex round-trips per span).TagHeavyis the only sub-benchmark showing a CPU improvement (-2.47%), confirming thesetTagsbatch lock optimization outweighs the config overhead when tag count is high.Reviewer's Checklist
System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.If this interacts with the agent in a new way, a system test has been added.make lintlocally.make testlocally.All generated files are up to date. You can check this by runningmake generatelocally.Unsure? Have a question? Request a review!