Skip to content

Avoid redundant allocations in V1 trace serialization - #13481

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
alexeyk/v1-utf8
Nov 21, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits into
masterfrom
alexeyk/v1-utf8

Conversation

@AlexeyKuznetsov-DD

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Avoid redundant UTF-8 encoding and tag-iterator allocation when serializing traces with the V1 intake protocol. Preserve the existing payload representation and string-table deduplication across value types.

Motivation

The V1 serializer converted pre-encoded strings to plain Strings before writing them, losing the cached UTF-8 encoding. Its two tag passes also created iterators for every span. These costs repeat across every serialized batch.

Additional Notes

The mapper retains String keys for content-based deduplication, but passes UTF8BytesString values directly to the writer on string-table misses. Tag counting and writing use callbacks with explicit state, and empty baggage and meta-struct maps skip entry-set traversal.

Related precedent: #13096 introduced the chunked serialization buffer used by this benchmark path.

Regression coverage verifies the UTF-8 writer path and decoded values for span and event attributes, cached HTTP status codes, explicit-status precedence, null-status fallback, and legacy event-tag exclusion.

Validation: ./gradlew :dd-trace-core:test --tests datadog.trace.common.writer.ddagent.TraceMapperV1PayloadTest — 39 tests passed.

Benchmark comparison at 1,000 traces per payload

The baseline run uses master without this patch; the optimized run includes the known-tag ID and HTTP-status presence-check follow-ups. Each payload contains 1,000 traces and 4,000 spans. The v0.4 column comes from the master run.

Both percentage columns measure the change to V1 optimized: (V1 optimized / baseline - 1) * 100. Negative values mean optimized V1 uses less.

Benchmark:

./gradlew :dd-trace-core:jmh -Pjmh.includes=TraceSerializerBenchmark -Pjmh.profilers=gc -PtestJvm=21

Allocation — KiB per payload

Cache URL type / cardinality v0.4 V1 master V1 optimized V1 master → opt v0.4 → opt
Cold String / same 2,156.9 2,378.9 1,957.0 -17.7% -9.3%
Cold String / distinct 2,257.9 2,661.4 2,239.6 -15.9% -0.8%
Cold UTF-8 / same 2,305.3 2,644.6 2,003.9 -24.2% -13.1%
Cold UTF-8 / distinct 2,425.7 2,927.3 2,286.4 -21.9% -5.7%
Cold LazyUrl / same 1,735.5 1,957.2 1,535.1 -21.6% -11.5%
Cold LazyUrl / distinct 1,959.9 2,457.8 1,817.0 -26.1% -7.3%
Cold StringBuilder / same 2,430.3 2,996.3 2,355.3 -21.4% -3.1%
Cold StringBuilder / distinct 2,780.9 3,278.6 2,638.0 -19.5% -5.1%
Warm String / same 891.2 1,238.4 816.4 -34.1% -8.4%
Warm String / distinct 1,154.0 1,432.7 1,010.6 -29.5% -12.4%
Warm UTF-8 / same 1,016.7 1,457.2 816.3 -44.0% -19.7%
Warm UTF-8 / distinct 1,048.8 1,651.4 909.0 -45.0% -13.3%
Warm LazyUrl / same 891.2 1,238.4 816.4 -34.1% -8.4%
Warm LazyUrl / distinct 1,028.9 1,432.7 1,010.6 -29.5% -1.8%
Warm StringBuilder / same 1,165.2 1,605.6 964.8 -39.9% -17.2%
Warm StringBuilder / distinct 1,302.4 1,799.6 1,159.0 -35.6% -11.0%

Serialization time — microseconds per payload

Cache URL type / cardinality v0.4 V1 master V1 optimized V1 master → opt v0.4 → opt
Cold String / same 1,714.8 1,453.1 1,342.6 -7.6% -21.7%
Cold String / distinct 1,933.1 1,506.5 1,387.4 -7.9% -28.2%
Cold UTF-8 / same 1,711.5 1,631.9 1,342.7 -17.7% -21.5%
Cold UTF-8 / distinct 1,733.7 1,675.9 1,265.0 -24.5% -27.0%
Cold LazyUrl / same 1,846.4 1,556.1 1,437.0 -7.7% -22.2%
Cold LazyUrl / distinct 2,115.3 1,789.3 1,490.3 -16.7% -29.5%
Cold StringBuilder / same 1,777.2 1,656.9 1,271.6 -23.3% -28.4%
Cold StringBuilder / distinct 1,834.6 1,732.2 1,443.4 -16.7% -21.3%
Warm String / same 1,759.3 1,436.6 1,339.5 -6.8% -23.9%
Warm String / distinct 1,784.0 1,547.1 1,378.5 -10.9% -22.7%
Warm UTF-8 / same 2,094.0 1,562.3 1,337.4 -14.4% -36.1%
Warm UTF-8 / distinct 2,207.1 1,611.7 1,148.7 -28.7% -48.0%
Warm LazyUrl / same 1,824.3 1,470.1 1,359.2 -7.5% -25.5%
Warm LazyUrl / distinct 2,018.7 1,481.0 1,311.4 -11.5% -35.0%
Warm StringBuilder / same 1,707.0 1,623.4 1,347.0 -17.0% -21.1%
Warm StringBuilder / distinct 1,906.3 1,732.7 1,317.4 -24.0% -30.9%

Allocation is calculated from JMH gc.alloc.rate.norm / 1024; cold allocation includes URL-refresh setup. Warm runs reuse URL values.

These are observed results from separate runs, with one measurement per configuration and no reported error estimates. The unchanged v0.4 control varied by -18.3% to +39.0% in time between runs, so timing differences should be treated as directional. The summaries do not record the JDK, JVM flags, exact revisions, or complete benchmark settings; full run provenance is still needed to establish a controlled before/after comparison.

Contributor Checklist

Jira ticket: N/A

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD 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 16, 2026
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD marked this pull request as ready for review November 16, 2026 20:25
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested review from a team as code owners November 16, 2026 20:25
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested review from dougqh and mcculls and removed request for a team November 16, 2026 20:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T20:54:22.997989Z 824bf48 Manual request
🔒 Security Review ✅ Completed 2026-11-16T20:54:37.227419Z 824bf48 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-prod-us1-3 datadog-prod-us1-3 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Static review supports preserved V1 payload encoding, string-table deduplication across value types, and tag traversal behavior. Allocation and timing improvements were not measured by this review.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 824bf48

@datadog-prod-us1-3

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Nov 16, 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.89 s 14.74 s [+0.2%; +1.8%] (maybe worse)
startup:insecure-bank:tracing:Agent 13.64 s 13.71 s [-1.1%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.78 s 17.47 s [+1.1%; +2.5%] (significantly worse)
startup:petclinic:iast:Agent 17.45 s 17.73 s [-2.4%; -0.8%] (maybe better)
startup:petclinic:profiling:Agent 17.29 s 17.32 s [-1.0%; +0.7%] (no difference)
startup:petclinic:sca:Agent 17.86 s 17.68 s [+0.1%; +1.9%] (maybe worse)
startup:petclinic:tracing:Agent 16.81 s 16.99 s [-2.0%; -0.1%] (maybe better)

Commit: 5d51182e · 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.

@AlexeyKuznetsov-DD

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 824bf4851a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 824bf4851a

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@mcculls mcculls left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring makes sense

Worth checking with @dougqh about the best way to use the new tag APIs, especially around using known tag-ids

@dougqh dougqh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The changes keep the payload the same, and every one removes work or makes a lookup cheaper:

  • Lookups by KnownTags ID return the same results as the string versions, and the EVENTS filter still matches tags that were set by name.
  • getHttpStatusCodeString() is already null for UNSET_STATUS, and TagMap drops null values, so the presence check is equivalent. The new tests cover both cases.
  • The callbacks capture nothing, TagMap.forEach doesn't create an iterator, and writeUTF8 reuses the cached bytes.

On the benchmarks, the allocation numbers are convincing. The timing table needs a caveat: each configuration ran once, the run provenance wasn't recorded, and the unchanged v0.4 control moved from −18% to +39% between runs. That's bigger than most of the reported V1 gains. Please either label the timing as directional or rerun baseline and head back to back with forks. I'm not blocking the merge on this. (#13502 proposes relaxing the rule for allocation-only claims.)

I'd also like to know where the JMH harness lives, so others can reproduce the numbers.

# Conflicts:
#	dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/TraceMapperV1.java
@AlexeyKuznetsov-DD

Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-11-21 16:47:46 UTC ℹ️ Start processing command /merge


2026-11-21 16:47:50 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-11-21 17:34:12 UTC ℹ️ MergeQueue: This merge request was merged

@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit ec95c90 into master Nov 21, 2026
692 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the alexeyk/v1-utf8 branch November 21, 2026 17:34
@github-actions github-actions Bot added this to the 1.70.0 milestone Nov 21, 2026
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.

3 participants