Repository navigation
Conversation
Config Audit |
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 4 Pipeline jobs failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed 🎯 Code Coverage (details) Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 369147d | Docs | View more details | Give us feedback! |
Add a reproducible benchmark covering plain StartSpanFromContext and Span.Finish across root, child, and dropped priority-0 spans using discardTransport to isolate tracer overhead.
Have StartSpanFromContext call (*tracer).startSpanWithContext directly instead of copying opts via options.Expand and allocating ChildOf and withContext closures. Move StartSpanOption parsing into an out-of-line parseStartSpanOptions helper so zero-option calls do not heap-allocate StartSpanConfig.
Add AttrRuntimeID to SpanAttributes and populate it in buildSharedAttrs so plain spans inherit runtime-id via read-only sharedAttrs instead of allocating SpanMeta.m. Emit runtime-id in payload_v1 alongside language, and skip redundant language and single-entry runtime-id global tag writes on the StartSpan hot path.
Return early in concentrator.newTracerStatSpan when a span is not top level, not measured, and has no flat meta tags. Pass shared empty maps when flat meta or metrics are nil so NewStatSpanWithConfig does not allocate fresh empty maps.
Call spn.setMetric directly instead of spn.SetTag when recording the sampling priority rate so the float64 value does not box into any.
Pre-allocate read-only single-entry maps for DecisionMaker values "-0" through "-13" so locally started root spans skip allocating a map in copyOnWriteSet. Track propagatingTagsReadOnly so setPropagatingTagUnsafe clones before mutating a cached entry.
… in trace
Embed inlineSpans [10]*Span and inlineChunk in trace so small traces
avoid a separate slice backing-array allocation in newTrace and avoid a
separate &chunk{} allocation on their first full flush.
Locally generated 128-bit trace IDs store 32-bit unix seconds followed by 32 zero bits in their upper 64 bits, so the 16-char upper hex string changes at most once per second. Cache it atomically to avoid allocating and hex-encoding a 32-byte string on every root span finish.
…mitChunk Embed single [1]*tracerStatSpan in tracerStatSpan so chunks with a single eligible stat span submit a slice backed by that entry instead of allocating a new slice in submitChunk.
When span pooling is disabled, allocate rootSpanBlock (Span, SpanContext, trace, spanCtx, tracerStatSpan) or childSpanBlock (Span, SpanContext, spanCtx) in a single heap allocation. Pooled spans clear s.context on acquire and keep allocating SpanContext independently so span pool recycling remains safe.
b17a1dd to
369147d
Compare
BenchmarksBenchmark execution time: 2026-11-25 18:56:06 Comparing candidate commit 369147d in PR branch Found 59 performance improvements and 9 performance regressions! Performance is the same for 348 metrics, 0 unstable metrics.
|
What does this PR do?
This PR cuts heap allocations and CPU time on
StartSpanFromContextand(*Span).Finishfor plain spans while keeping all public APIs and behavior unchanged:StartSpanFromContextto(*tracer).startSpanWithContext. ParseStartSpanOptionslices out of line inparseStartSpanOptionsso zero-option calls do not allocateStartSpanConfig.runtime-idintoSpanAttributes(AttrRuntimeID) so plain spans share it through read-onlysharedAttrsinstead of allocatingSpanMeta.m. Skip redundantlanguageand single-entryruntime-idglobal tag writes on the hot path.concentrator.newTracerStatSpanbefore callingNewStatSpanWithConfig, and pass shared empty maps when flat meta or metrics are nil._dd.p.dmpropagating-tag maps ("-0"through"-13"), embedinlineSpansandinlineChunkintrace, and callsetMetricinstead ofSetTaginprioritySampler.apply.Span,SpanContext,trace,spanCtx, andtracerStatSpaninto one allocation (rootSpanBlockandchildSpanBlock). Avoid allocating a 1-element slice insubmitChunk, and cachetraceID.UpperHex()per second for locally generated 128-bit trace IDs.BenchmarkPlainSpanFromContextand unit tests forAttrRuntimeID,UpperHex()caching, and cached_dd.p.dmmap immutability.Motivation
StartSpanFromContextand(*Span).Finishaccount for over 85% of CPU time and most allocations on a plain span.Median of 6 runs on Apple M5 Pro (
go test -run='^$' -bench='BenchmarkPlainSpanFromContext' -benchmem -count=6 ./ddtrace/tracer):BenchmarkPlainSpanFromContext/RootBenchmarkPlainSpanFromContext/ChildBenchmarkPlainSpanFromContext/RootDroppedP0BenchmarkPlainSpanFromContext/ChildDroppedP0Existing benchmarks also improved:
BenchmarkSpanLifecycle/Minimalwent from 2689 ns/op and 77 allocs/op to 2338 ns/op and 67 allocs/op (-13.1% time), andBenchmarkStartSpanwent from 496 ns/op and 14 allocs/op to 443 ns/op and 11 allocs/op (-10.7% time).Reviewer's Checklist
make lintlocally.make testlocally.make generatelocally.make fix-moduleslocally.