GeezerVison is showing github.com — Dispatch extraction on header constants instead of comparing names by dougqh · Pull Request #13613 · DataDog/dd-trace-java
Conversation
dougqh
commented
Nov 21, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
What Does This Do
Adds HeaderSchema, an enum of the headers the tracer knows by name, and dispatches extraction on those constants instead of comparing header names. Extracted contexts are unchanged.
Stacked on #13606.
Motivation
A 30-minute CPU profile of a Kafka consumer had ~6% of the consumer thread's tracer time in header-name comparisons: each record's headers were compared, case-insensitively, against several names by the span id cache, the baggage extractor and the Datadog and W3C interpreters, about 30 equalsIgnoreCase calls per record. #13605 already matches each key once against the propagators' declared names; this carries the result of that match along as a constant, so later code switches on it.
Additional Notes
HeaderSchema (components/context): Datadog, W3C, baggage, B3, Haystack, X-Ray and DSM headers, plus the forwarding / user agent / client IP headers every style reads. Each constant has its lower-case name and ASCII bytes. Its ordinal() is a dense index: carrier-specific forms of a name (a Netty AsciiString, a gRPC Metadata.Key) belong in arrays indexed by ordinal next to their instrumentations, which keeps the enum dependency-free.
CarrierKeys records the constant of every declared name that is a known header, and returns it from header(String) / headerAscii(ByteBuffer) (with an identity shortcut, since carriers that matched a key's bytes pass the declared name itself).
- The composite propagator's cache records each pair's constant (
IndexedCarrier.header).
KeyClassifier.accept(HeaderSchema, key, value), defaulting to the by-name accept. ContextInterpreter implements it: a style's own headers go straight to its handling, the shared forwarding and user agent headers to their handlers, and other known headers to the common tail (client IP, header tags, mapped baggage). A null constant, header-name logging, or a style that doesn't classify the header takes the by-name path, so the two paths can't disagree.
- Datadog, W3C and Haystack classify their headers (
x-amzn-trace-id, read only with AWS propagation, stays by name); None, with no headers of its own, sends every known header to the shared handling. B3 and X-Ray stay by name: their accept wraps the shared handling and the common tail in a try/catch, which the generic dispatch would move outside it.
ExtractionCache's span id check, the single-extractor path and the baggage extractor use the constants too.
- Tests:
HeaderSchemaTest; CarrierKeysTest / CarrierCacheTest for constants; ExtractorKeysForkedTest checks, for every style (with its own keys and with every known header) and for the compound Datadog + W3C extractor reading the carrier in place, that dispatching on constants extracts the same context as by name. Propagation and baggage tests pass unchanged (1,431, including the compound-extraction golden test, which goes through the composite propagator and so through the constant path).
- The carrier cache stores each pair's constant as a byte (
ordinal() + 1, 0 for none), not a second reference array, keeping the per-extraction cost to a byte[8].
- Numbers: neutral on CPU, so the case for this PR is structural.
- JMH, this PR alone against Read the composite propagator's carrier cache in place #13606:
KafkaFetchedHeadersBenchmark within noise (−1.4% to +2.8%, 3 forks on an 8 vCPU VM). HeaderPathBenchmark single-threaded on a laptop, two runs: datadog −1.6% / −0.6%, both −1.1% / 0.0%, all within run-to-run noise. An 8-thread run on the VM showed datadog +4.4% and both −6.9%, but neither reproduced single-threaded.
- The profile's ~6% for name comparisons overstated what removing them saves: most
equalsIgnoreCase calls exit on identity or length, and JFR attributed some of their cost to regionMatchesCI, which never ran.
- Allocation: the per-pair constant costs a
byte[8] per extraction (about 24 B).
- What it enables: the value-views series (Let carriers hand parse-only header values as transient views #13618–Hand parse-only Kafka header values to extraction as views #13620), which hands parse-only header values to extraction as views by their constant (−104 B per Kafka record), and, next, looking up a style's own headers by ordinal instead of every interpreter walking every pair.
- Laptop Kafka macrobenchmark, bundled with Match x-datadog-tags keys by their characters and parse tid once #13608 and Check tracestate members in one pass and skip t.* keys the merge never reads #13610: consumer +3.7%, enricher +1.7% (within noise).
🤖 Generated with Claude Code
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
datadog-official
Bot
commented
Nov 21, 2026
•
edited by datadog-datadog-prod-us1
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
🎯 Code Coverage (details) • Patch Coverage: 87.19% • Overall Coverage: 59.65% (+0.05%)
This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2976862 | Docs | Give us feedback!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dd-octo-sts
Bot
commented
Nov 21, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
🟡 Java Benchmark SLOs — Performance SLO warning (near threshold)
| Suite |
Status |
| Startup |
🟡 warning |
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.04 s |
14.01 s |
[-0.5%; +0.8%] (no difference) |
| startup:insecure-bank:tracing:Agent |
13.00 s |
13.02 s |
[-0.8%; +0.5%] (no difference) |
| startup:petclinic:appsec:Agent |
17.97 s |
17.66 s |
[+0.8%; +2.6%] (maybe worse) |
| startup:petclinic:iast:Agent |
17.83 s |
17.78 s |
[-0.5%; +1.1%] (no difference) |
| startup:petclinic:profiling:Agent |
17.68 s |
17.42 s |
[+0.3%; +2.7%] (maybe worse) |
| startup:petclinic:sca:Agent |
17.97 s |
17.88 s |
[-0.4%; +1.4%] (no difference) |
| startup:petclinic:tracing:Agent |
16.89 s |
16.92 s |
[-1.2%; +0.9%] (no difference) |
Commit: 2976862a · 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
pr-commenter
Bot
commented
Nov 21, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Kafka / producer-benchmark
Parameters
|
Baseline |
Candidate |
| baseline_or_candidate |
baseline |
candidate |
| git_branch |
dougqh/kafka-carrier-cache |
dougqh/header-schema |
| git_commit_date |
1795553620 |
1795553623 |
| git_commit_sha |
77290f9 |
2976862 |
See matching parameters
|
Baseline |
Candidate |
| ci_job_date |
1795555096 |
1795555096 |
| ci_job_id |
2298335622 |
2298335622 |
| ci_pipeline_id |
156344360 |
156344360 |
| cpu_model |
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz |
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz |
| jdkVersion |
11.0.31 |
11.0.31 |
| jmhVersion |
1.36 |
1.36 |
| jvm |
/usr/lib/jvm/java-11-openjdk-amd64/bin/java |
/usr/lib/jvm/java-11-openjdk-amd64/bin/java |
| jvmArgs |
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost |
*.localhost |
| kernel_version |
Linux runner-zfyrx7zua-project-304-concurrent-0-b7j85gkr 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux |
Linux runner-zfyrx7zua-project-304-concurrent-0-b7j85gkr 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux |
| vmName |
OpenJDK 64-Bit Server VM |
OpenJDK 64-Bit Server VM |
| vmVersion |
11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu |
11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu |
Summary
Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.
See unchanged results
| scenario |
Δ mean throughput |
| scenario:not-instrumented/KafkaProduceBenchmark.benchProduce |
same |
| scenario:only-tracing-dsm-disabled-benchmarks/KafkaProduceBenchmark.benchProduce |
same |
| scenario:only-tracing-dsm-enabled-benchmarks/KafkaProduceBenchmark.benchProduce |
same |
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
pr-commenter
Bot
commented
Nov 21, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Kafka / consumer-benchmark
Parameters
|
Baseline |
Candidate |
| baseline_or_candidate |
baseline |
candidate |
| git_branch |
dougqh/kafka-carrier-cache |
dougqh/header-schema |
| git_commit_date |
1795553620 |
1795553623 |
| git_commit_sha |
77290f9 |
2976862 |
See matching parameters
|
Baseline |
Candidate |
| ci_job_date |
1795555048 |
1795555048 |
| ci_job_id |
2298335628 |
2298335628 |
| ci_pipeline_id |
156344360 |
156344360 |
| cpu_model |
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz |
Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz |
| jdkVersion |
11.0.31 |
11.0.31 |
| jmhVersion |
1.36 |
1.36 |
| jvm |
/usr/lib/jvm/java-11-openjdk-amd64/bin/java |
/usr/lib/jvm/java-11-openjdk-amd64/bin/java |
| jvmArgs |
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=15002 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=15002 -Dhttp.nonProxyHosts=localhost |
*.localhost |
| kernel_version |
Linux runner-zfyrx7zua-project-304-concurrent-0-gxqh2ljj 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux |
Linux runner-zfyrx7zua-project-304-concurrent-0-gxqh2ljj 6.8.0-1031-aws #33~22.04.1-Ubuntu SMP Thu Jun 26 14:22:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux |
| vmName |
OpenJDK 64-Bit Server VM |
OpenJDK 64-Bit Server VM |
| vmVersion |
11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu |
11.0.31+11-post-1ubuntu1-22.04.2-Ubuntu |
Summary
Found 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics.
See unchanged results
| scenario |
Δ mean throughput |
| scenario:not-instrumented/KafkaConsumerBenchmark.benchConsume |
same |
| scenario:only-tracing-dsm-disabled-benchmarks/KafkaConsumerBenchmark.benchConsume |
same |
| scenario:only-tracing-dsm-enabled-benchmarks/KafkaConsumerBenchmark.benchConsume |
unsure [-9267.705op/s; -1266.995op/s] or [-4.972%; -0.680%] |
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 21, 2026
An enum of the carrier keys propagators read (Datadog, W3C, baggage, B3,
Haystack, X-Ray, DSM, and the forwarding / user agent / client IP headers
every style reads), each with its lower-case name and ASCII bytes. Its
ordinal is a dense index for per-header arrays, which keeps carrier-specific
forms (a Netty AsciiString, a gRPC Metadata.Key) next to their
instrumentations.
CarrierKeys records the constant of every declared name that is a known
header and returns it from header(String) / headerAscii(ByteBuffer), so
code handling several headers can switch on it instead of comparing names.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The composite propagator's cache records each key's HeaderSchema constant
(IndexedCarrier.header), and passes it along:
- KeyClassifier gains accept(HeaderSchema, key, value), defaulting to the
by-name accept.
- ContextInterpreter's implementation sends a style's own headers straight
to its handling, the shared forwarding / user agent headers to their
handlers, and other known headers to the common tail (client IP, header
tags, mapped baggage). A null constant, header-name logging, or a style
that doesn't classify the header takes the by-name path.
- The Datadog and W3C interpreters classify their headers this way; the
other styles keep the by-name path for now.
- ExtractionCache's span id check, the single-extractor path and the
baggage extractor use the constants too.
A profile of a Kafka consumer had ~6% of the consumer thread's tracer time
in these name comparisons (about 30 equalsIgnoreCase calls per record).
ExtractorKeysForkedTest checks that, for every style and for the compound
extractor, dispatching on constants extracts the same context as by name.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The carrier cache kept a HeaderSchema[] beside its pairs, a second
reference array per extraction (about 48 bytes for the usual 8 pairs).
With fewer than 127 constants, ordinal() + 1 fits in a byte, so it's a
byte[] instead (24 bytes).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Haystack classifies its trace / span / parent id headers like Datadog and
W3C; None has no headers of its own, so every known header gets the shared
handling directly. B3 and X-Ray stay by name: their accept wraps the shared
handling and the common tail in its try/catch, which the generic dispatch
would move outside it. ExtractorKeysForkedTest's per-style equivalence
check covers the two new styles.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Same as CarrierKeys.contains: keys are usually lower case already, so
String.equals (intrinsified, with an identity check) catches them before
the case-insensitive comparison.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…racter
CarrierKeys.header(String) and contains(String) compared each declared name
with equals and then, on a miss, ignoring case. Most keys a carrier offers are
no declared name, so every key as long as a declared name paid a
case-insensitive comparison against each of them: about half of the header
key matching on a Kafka consumer's main thread (regionMatchesCI under
CarrierKeys.header).
As the byte path already does, the String path now compares exactly first
and only compares ignoring case if the key has an upper-case character at
all. Declared names and prefixes are stored lower case, so a key without one
can only match exactly. (Java's case-insensitive comparison also folds a few
non-ASCII characters onto ASCII letters; header names are ASCII tokens, and
the byte path already matches no non-ASCII key.)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
No deployments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|