Skip to content

Match x-datadog-tags keys by their characters and parse tid once - #13608

Draft
dougqh wants to merge 1 commit into
dougqh/w3c-traceparent-no-throwfrom
dougqh/lazy-datadog-tags
Draft

dougqh wants to merge 1 commit into
dougqh/w3c-traceparent-no-throwfrom
dougqh/lazy-datadog-tags

Conversation

@dougqh

@dougqh dougqh commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Speeds up the x-datadog-tags parse on extraction. Known keys are matched by their characters instead of being interned, the _dd.p.tid value is validated and parsed into the trace id's high-order bits in one pass, and character validation uses lookup tables. Accept/reject decisions, propagation errors and the resulting tags are unchanged.

Stacked on #13356.

Motivation

In a 30-minute CPU profile of a Kafka consumer (10% sampled upstream traces), parsing x-datadog-tags was ~12% of the consumer thread's tracer time. Within it: value caching 24%, character validation 21%, the loop and its chain of ~13 TagKey.equals 16%, tid validation (hex parse) 14%, TagKey.from interning 13.5%, building PTags 11%. A Datadog producer typically sends only _dd.p.dm and _dd.p.tid, and both are needed at extraction (the decision maker for the sampling state, the high-order bits for the trace id), so the gain has to come from parsing them more cheaply rather than deferring them.

Additional Notes

  • Key matching: a key range is compared against the known keys' full _dd.p.* names (taken from the existing TagKey constants) by length, then characters. Only other _dd.p.* keys go through TagKey.from. Keys without the prefix, or with nothing after it, are ignored as before.
  • _dd.p.tid: validated (16 lower-case hex digits) and parsed into a long once, instead of being wrapped in a cached TagValue and parsed again by PTags. PTags makes the hex TagValue on first read (injection, header size), published with a CAS that can't overwrite a concurrent updateTraceIdHighOrderBits. An all-zero tid is still carried verbatim.
  • Validation: scan replaces validateCharsUntilSeparatorOrEnd with the same accepted sets and edge cases, from tables built from the existing isAllowedKeyChar / isAllowedValueChar, rather than IntPredicate method references.
  • _dd.p.dm, _dd.p.ts, the org marker and the LLMObs tags keep their cached or uncached TagValues, as before.
  • Tests: the existing propagation tests pass unchanged (1,422, including the compound-extraction golden test and DatadogPropagationTagsTest's malformed-tid rows). DatadogTagsKeyMatchingTest adds rows for what the raw matcher decides (prefix-only and unprefixed keys, a near-miss key, unknown keys, upstream_services, an all-zero tid, values containing =); its expectations were recorded by running it against the previous parse.
  • Numbers: PropagationTagsBenchmark / HeaderPathBenchmark A/B to follow.

🤖 Generated with Claude Code

The x-datadog-tags parse interned every key (TagKey.from) and compared it
against a chain of ~13 known keys, cached every value, and parsed the tid
twice: once to validate it, then again into the trace id's high bits.
In a Kafka consumer profile that was ~12% of the consumer thread's tracer
time.

Known keys are now matched on the raw range by length, then characters,
against the existing TagKey constants; only other _dd.p.* keys are
interned. The tid is validated and parsed into a long in one pass, and its
hex TagValue is made only when something reads it (injection, header size).
Character validation uses lookup tables instead of IntPredicate method
references. Accept/reject decisions, errors and the tags produced are
unchanged; DatadogTagsKeyMatchingTest's rows were recorded against the
previous parse.

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 21, 2026
@datadog-prod-us1-6

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Nov 21, 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.09 s 14.03 s [-0.5%; +1.3%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 13.02 s [-1.2%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 17.72 s 17.56 s [-0.0%; +1.9%] (no difference)
startup:petclinic:iast:Agent 17.52 s 17.74 s [-2.0%; -0.5%] (maybe better)
startup:petclinic:profiling:Agent 17.42 s 17.17 s [+0.3%; +2.6%] (maybe worse)
startup:petclinic:sca:Agent 17.74 s 17.58 s [-0.1%; +1.9%] (no difference)
startup:petclinic:tracing:Agent 16.24 s 16.72 s [-7.2%; +1.5%] (no difference)

Commit: a382d5d2 · 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