Skip to content

Check an inherited ot member's consistency once, not on every write - #13664

Draft
dougqh wants to merge 2 commits into
dougqh/tracestate-lower-priority-mergefrom
dougqh/otel-member-check-once
Draft

dougqh wants to merge 2 commits into
dougqh/tracestate-lower-priority-mergefrom
dougqh/otel-member-check-once

Conversation

@dougqh

@dougqh dougqh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Remembers, per pending-check combination, whether an inherited ot tracestate member comes out unchanged under the sampling consistency checks. Injection then doesn't redo that check for every header it writes.

Motivation

When a trace is relayed (a Datadog context with a lower-priority tracestate merged in, as for every Kafka consume → produce record), injection writes the unparsed ot member back. First it confirms that parsing the member and applying the pending checks would leave it unchanged: hex scans of rv and th, plus a threshold parse. That check:

  • ran twice per injected tracestate, once from estimateHeaderSize and once from appendOtelAndVendorMembers,
  • ran again on every injection, because nothing kept the answer.

In a JFR profile of a Kafka enricher, it was about 40% of the tracer's inject time (about 146 of 380 inject samples).

W3CTracestate already remembers the raw member's position the same way (rawPosition). This adds the equivalent for the unchanged check: 4 "checked" and 4 "unchanged" bits in one byte. Racing writers can only drop each other's bits, which costs a recheck, never a wrong answer.

Results

New TracestateRelayBenchmark (single thread; one op = one relayed trace: parse x-datadog-tags, merge the tracestate at lower priority, encode the outbound tracestate). It's committed separately, before the fix, so both sides run the same benchmark. 3 forks × 5 iterations, stable per fork:

base this PR
withOtel ~705 ns/op ~628 ns/op (−11%)
ddOnly 422 ± 16 ns/op 409 ± 10 ns/op (no change)
allocation 888 / 744 B/op unchanged

The written output is byte-identical: only the repeated check is gone.

End to end (Kafka enricher, 10% sampling, 5 rotated reps): a combined build with #13662 and #13664 on the 4i roll-up cuts tracer cost per record from 3.53 to 3.36 µs at 1g (+3.5% throughput) and from 4.89 to 4.70 µs at 96m (+3.2%); 4j beat 4i in 8 of 10 paired reps. The two PRs were measured together, so this is their combined effect. The consumer, which doesn't inject, is flat (2.56 vs 2.58 µs at 1g).

Additional Notes

🤖 Generated with Claude Code

dougqh and others added 2 commits November 24, 2026 10:52
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Injecting a relayed trace writes its tracestate's unparsed ot member, after
checking that parsing it under the pending sampling checks would leave it
unchanged. That check (hex scans of rv and th, a threshold parse) ran twice
per injected header, once for the size estimate and once for the write, and
again on every injection, because nothing kept the answer. In a Kafka
enricher profile it was about 40% of the tracer's inject time.

W3CTracestate now keeps the answer per pending-check combination in a byte,
like the raw member's position is already kept.

TracestateRelayBenchmark.relay, 3 forks x 5 iterations: withOtel 706 -> 628
ns/op (-11%), ddOnly unchanged within noise, allocation unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh dougqh added comp: core Tracer core tag: performance Performance related changes type: refactoring tag: ai generated Largely based on code generated by an AI or LLM labels Nov 24, 2026
@datadog-official

datadog-official Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 59.88% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 870769b | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.81 s 14.72 s [-0.2%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 13.60 s 13.74 s [-1.7%; -0.4%] (maybe better)
startup:petclinic:appsec:Agent 17.16 s 16.98 s [+0.2%; +1.9%] (maybe worse)
startup:petclinic:iast:Agent 16.89 s 17.14 s [-2.4%; -0.5%] (maybe better)
startup:petclinic:profiling:Agent 16.18 s 16.65 s [-7.1%; +1.4%] (no difference)
startup:petclinic:sca:Agent 17.17 s 16.90 s [+0.7%; +2.5%] (maybe worse)
startup:petclinic:tracing:Agent 16.14 s 16.29 s [-1.6%; -0.3%] (maybe better)

Commit: 870769bf · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: ai generated Largely based on code generated by an AI or LLM tag: performance Performance related changes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant