Repository navigation
Conversation
1118e81 to
8d15876
Compare
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
8d15876 to
49e3eee
Compare
Kafka / producer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
Kafka / consumer-benchmarkParameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 3 metrics, 0 unstable metrics. See unchanged results
|
CarrierKeys.nameAscii read every byte through ByteBuffer.get and folded its case, against the union of all propagators' names. For a heap buffer it now compares the backing array's bytes exactly with each name's precomputed lower-case ASCII bytes, and only compares ignoring case if the key has an upper-case byte at all. In KafkaFetchedHeadersBenchmark this more than halves the matcher's cost: fetched headers with the accessor go from -3.6% to -8.3% against #13600 with three application headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 687bd775ca
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| jmh sourceSets.main_java17.output | ||
| jmh group: 'org.apache.kafka', name: 'kafka-clients', version: '3.8.0' | ||
| jmh project(':dd-trace-core') |
There was a problem hiding this comment.
Regenerate the Kafka module's dependency lockfile
Adding the JMH plugin and these dependencies introduces new benchmark dependency configurations, but this commit leaves the module's gradle.lockfile unchanged, with no JMH configuration entries. The repository enables lockAllConfigurations(), and the sibling Kafka 0.11 module explicitly locks its JMH configurations. Regenerate and include the affected lockfiles so the new benchmark dependency graph is pinned, as required by the dependency-change rule in AGENTS.md.
AGENTS.md reference: AGENTS.md:L69-L70
Useful? React with 👍 / 👎.
| if (decoder == null && header instanceof BufferedHeaderFields) { | ||
| BufferedHeaderFields fields = (BufferedHeaderFields) header; | ||
| key = RecordHeaderAccess.key(header, fields); | ||
| value = RecordHeaderAccess.utf8Value(header, fields); |
There was a problem hiding this comment.
Preserve overridden accessors on RecordHeader subclasses
When a header subclasses RecordHeader and overrides key() or value(), it inherits BufferedHeaderFields from the instrumented superclass, so this branch bypasses those overrides and extracts the superclass's private fields instead. For example, a subclass initialized with trace-ID bytes "123" but overriding value() to return "456" previously extracted 456 and now extracts 123, associating the span with the wrong trace. Restrict the field-access fast path to the exact Kafka implementation, or otherwise ensure its accessors have not been overridden.
Useful? React with 👍 / 👎.
5bbdf4e to
4a70a9b
Compare
4a70a9b to
41169b2
Compare
307f5f9 to
cb89960
Compare
1fdefac to
ca1a7a0
Compare
KafkaFetchedHeadersBenchmark drains a poll batch through the 3.8 TracingIterator with headers that hold slices of a record-batch buffer, as a fetch builds them, so Kafka's lazy key decode and value copy, which extraction triggers, are measured. Params: headerShape (fetched / built) and appHeaders (0 / 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RecordHeaderInstrumentation installs BufferedHeaderFields on Kafka's RecordHeader (a structural change, like TaskWrapper), with getters for its key, keyBuffer, value and valueBuffer fields. Extraction reads fetched headers through it: known propagation header keys resolve to their name constants and values decode once from the fetch buffer, skipping RecordHeader's key decode and value copy. Headers without the accessor (loaded before the agent, other Header types) and Base64-encoded headers take the existing path. KafkaFetchedHeadersBenchmark gains a fetchedAccessor shape: the same fetched headers with the accessor, as under the agent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RecordHeaderInstrumentation declares BufferedHeaderFields with getters for RecordHeader's key, keyBuffer, value and valueBuffer, installed with installFieldAccessors from a WithStructuralChange instrumentation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
forEachKey had a second, near-duplicate loop for UTF-8 headers. One loop now takes the buffered path for a header the agent gave BufferedHeaderFields (when not decoding Base64) and the key()/value() path otherwise. The known-keys list uses PathwayContext's constant and says it's only a fast path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A RecordHeader subclass inherits the accessor interface, but may override key() or value(), which reading the raw fields would bypass. The buffered path now requires exactly RecordHeader; other types, subclasses included, go through key() and value(). Checking the exact class first also keeps the interface test constant once compiled, instead of a secondary-supers lookup per header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…afka's accessors Requiring exactly RecordHeader was stricter than needed: what matters is whether a subclass overrides key() or value(). RecordHeaderAccess.bufferedFields checks exactly RecordHeader first (the usual case, constant once compiled), and for any other class with the accessor, whether it keeps Kafka's own key() and value(), computed once per class in a ClassValue declared as a helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ype directly Use assertInstanceOf in the forked test and import its Kafka and java.util types: imports don't load classes, so the nesting in UnderAgent is what keeps RecordHeader unloaded until the agent is installed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BufferedHeaderFields' getters are named for the fields they read, so the getter/field pairs go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ca1a7a0 to
cdee736
Compare
There was a problem hiding this comment.
More details
Buffered extraction retains the existing key()/value() fallback for headers without accessors and for Base64 decoding. Static analysis identified no actionable defect; runtime behavior was not exercised.
🤖 Bits Code Review · Commit cdee736
mcculls
left a comment
There was a problem hiding this comment.
Came up with an alternative suggestion in #13656 (comment)
What Does This Do
The Kafka 3.8+ consumer's context extraction reads fetched record headers straight from the record-batch buffer, instead of through
RecordHeader.key()andvalue():x-datadog-*,traceparent,tracestate,baggage, the DSM and time-in-queue headers) resolves to that name's constant, with no decoding;byte[]copy.Extraction sees the same keys and values as before.
Motivation
A fetched
RecordHeaderholds slices of the fetch buffer and decodes lazily:key()builds aStringandvalue()copies the bytes into a new array, for every header the tracer visits, and extraction then decodes that array into anotherString. Profiling a Kafka consumer (in-review dense-store and header stacks, 10% sampling) attributed about 11 GiB per run, a third of all tracer allocation, to those three steps (RecordHeader.value3.4 GiB,RecordHeader.key4.1 GiB, our value decode 3.5 GiB).Additional Notes
Stacked on Add FieldAccessors to read a library class's private fields without reflection #13656, which adds
FieldAccessors(reading a library class's private fields without reflection) and generates muzzle references for the fields it reads. This PR is its first user.RecordHeaderInstrumentationdeclaresBufferedHeaderFields(a new bootstrap interface) with getters forRecordHeader'skey,keyBuffer,valueandvalueBuffer. ARecordHeaderloaded before the agent, or with a different layout, keeps its structure, and its headers take the existing path.RecordHeaderAccessreads those fields. It never writes them or moves a buffer's position, so the application's ownkey()/value()calls behave as before, and it doesn't keep any buffer reference past the call (each would keep the whole fetch buffer alive). Already-decoded fields, direct buffers, otherHeaderimplementations and Base64-encoded headers take the existing path.Subclasses: a
RecordHeadersubclass inherits the accessor, but may overridekey()orvalue()(say, to decrypt).RecordHeaderAccess.bufferedFieldschecks for exactlyRecordHeaderfirst (the usual case, constant once compiled). Any other class with the accessor uses its fields only if it keeps Kafka's ownkey()andvalue(), computed once per class in aClassValue. Otherwise the header is read through its overrides.Muzzle checks
RecordHeader's four fields across the whole Kafka range, generated from theinstallFieldAccessorscall (Add FieldAccessors to read a library class's private fields without reflection #13656). The accessor install is its own module, so a version without the fields skips only it, and extraction falls back tokey()/value().Lockfile: the module's
gradle.lockfilenow locks the benchmark's JMH configurations.Scope of the win: the savings apply with the default configuration. Other tracer code on the same record still calls the header's own
key()/value()when it's enabled: Data Streams Monitoring's payload sizing (Utils.computePayloadSizeBytes, on every header), time-in-queue (extractTimeInQueueStart, vialastHeader), and DSM transaction extractors. With DSM on, most of the key and value savings go away again. A natural follow-up is for payload sizing to read the buffers' lengths throughBufferedHeaderFieldsinstead of materializing them.One loop:
TextMapExtractAdapter.forEachKeychooses the buffered path per header (a header withBufferedHeaderFields, when not decoding Base64) and otherwise takes thekey()/value()path, so there's one loop for both.RecordHeaderAccess's known-keys list is only a fast path: a name missing from it costs a decode, never correctness.Tests:
RecordHeaderAccessTestcovers the read logic over realRecordHeaders (fetched slices with offsets, already-materialized fields, missing and direct-buffer values, unknown keys, state left untouched) and the adapter's output againstkey()/value().RecordHeaderInstrumentationForkedTestchecks the installed accessor under the agent. A forked test checks that a subclass overridingvalue()is read through its override.KafkaFetchedHeadersBenchmark(first commit; the module's first JMH benchmark) drains a poll batch throughTracingIteratorover headers in their fetched shape, rebuilt each op as each fetch builds them.headerShape:fetchedis today's path;fetchedAccessoris the same headers with the accessor, as under the agent (JMH runs without it, so the getters arestatic finalmethod handles there, which compile to the same field reads);builtis pre-built headers likeKafkaConsumeScenariosBenchmark's.appHeaders{0, 3} adds headers no propagator reads.Local smoke run (1 fork, JDK 21), per record:
fetchedfetchedAccessorbuiltA 3-fork run on an 8 vCPU VM confirmed the allocation (−734 B, −19% per record with no application headers; −867 B with three) but showed no clear time change there. With no application headers, fetched headers now allocate the same as pre-built ones. The remaining 168 B with three application headers is Kafka decoding keys nothing reads, which the classifier follow-up skips.
Kafka macrobenchmark (laptop): consumer and enricher on a local broker, 10% sampled upstream traces, 256m heap, v0.5 protocol, 3 reps; the in-review dense-store/TagLookup stack with and without these three commits (nothing else differs):
A JFR allocation profile of the consumer confirms the copies are gone: what the agent allocates under extraction's header loop drops from 6.7 GiB to 0.24 GiB (Kafka's header iterator), and tracer-attributed allocation per run from 31.7 to 24.2 GiB (−24%). The largest remaining site is the value strings themselves (
RecordHeaderAccess.utf8Value, 5.3 GiB), which the follow-ups address.Possible follow-up:
BufferedHeaderFieldscould move from internal-api into the Kafka module. Add FieldAccessors to read a library class's private fields without reflection #13656 now injects a module's accessor interface as a helper, so it no longer has to be on the bootstrap class path.Follow-ups, stacked on this:
🤖 Generated with Claude Code