Skip to content

Add a bounded, per-parse StringCanonicalizer to the toolbox (FFE optimization) - #13588

Open
dougqh wants to merge 1 commit into
dougqh/toolbox-hash-spreadfrom
dougqh/toolbox-string-canonicalizer
Open

dougqh wants to merge 1 commit into
dougqh/toolbox-hash-spreadfrom
dougqh/toolbox-string-canonicalizer

Conversation

@dougqh

@dougqh dougqh commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Adds datadog.trace.util.StringCanonicalizer to components/toolbox. It shares one String instance per distinct text within one parse. canonical(char[], offset, length) reads from a parser's character buffer and allocates only on a text's first occurrence. canonical(String) serves parsers that only hand out strings. Both share one table.

Two bounds keep the cost of a parse predictable, whatever the input:

  • Length: texts longer than maxLength (default 128) are neither hashed nor shared.
  • Probes: a lookup gives up and returns an unshared copy after comparing 16 strings with its hash code, or after 256 slots in all.

Giving up only costs sharing: the result is always equal to the text.

Adds StringCanonicalizerBenchmark (internal-api JMH).

Motivation

Long-lived parsed state, such as a configuration that stays in the old generation until the next one replaces it, pays for every duplicate string in memory and in marking work for as long as it lives. dd-openfeature's version (#13553) takes the scale flag configuration from 27.4 to 21.3 MB retained (−22% bytes, −30% objects), and allocates 4.6% less per parse. Remote config, sampling rules and probe configurations also keep parsed JSON for a long time, so this is a shared need.

This is the generalized version, with the review findings on #13553 fixed:

Sharing stays per instance. It is never JVM-wide like String.intern(), because parsed texts can be customer data, such as targeting ids.

Measured (Bits, StringCanonicalizerBenchmark, JDK 21, 3 forks per arm, 4 threads, 3×5 s warmup and 5×5 s measurement, -prof gc, steal median 0.3%). Per token: median fork in ns [fork range], then B:

Shape, distinct newString canonicalizer hashMap original (#13553)
keys, 1k 13.0 [12.7–13.0], 56 70.3 [69.8–82.6], 21.7 64.2 [63.4–65.6], 68.1 77.8 [77.3–90.9], 21.7
keys, 10k 13.1 [12.9–13.6], 56 105 [83.5–106], 27.1 90.7 [88.4–93.0], 67.3 119 [97.3–120], 27.1
ids, 1k 20.8 [20.8–20.9], 80 83.5 [81.4–83.9], 27.7 81.5 [80.9–82.2], 92.1 84.0 [82.8–84.6], 27.7
ids, 10k 19.4 [18.8–21.0], 80 108 [106–109], 33.1 118 [115–118], 91.3 104 [104–106], 33.1
collisions, 1k 17.9 [17.8–18.0], 64 198 [195–208], 63.8 293 [285–293], 82.2 8,296 [8,188–8,498], 23.7
collisions, 10k 18.3 [17.9–18.5], 72 198 [190–199], 72.0 492 [490–500], 89.3 77,779 [76,831–77,854], 31.1

Additional Notes

Contributor Checklist

🤖 Generated with Claude Code

@dougqh dougqh added type: feature Enhancements and improvements comp: core Tracer core tag: performance Performance related changes tag: ai generated Largely based on code generated by an AI or LLM labels Nov 20, 2026
@pr-commenter

pr-commenter Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

LLM Validation

LLM Validation Gate — java-agent-instructions

✅ PASS

  • No blocking-case regressions; the quality change is within noise (baseline/candidate confidence intervals overlap).
  • Advisory: the candidate introduced a bad signal on 1 case(s) that the baseline did not — surfaced for review (see Cases); it does not block on its own.

6 case(s) · quality 81.1 → 81.6 (+0.5) · win-rate 47% [44%–50%]

Details — analysis and per-case results

Analysis

Changed instruction file(s): AGENTS.md.

1 case(s) dipped but stayed within the pass bar.

  • java-core-validation-001 (advisory): won 33% of blind comparisons, quality -1.7. ⚠️ Introduced a new bad signal (advisory).
    • Asked: My PR changes dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java and updates these tests: -
    • Tripped 1 bad signal(s):
      • Recommends disabling checks or ignoring failures to get a passing build.
    • Baseline answer: Run these from the repo root, in this order. 1. Format the code shell ./gradlew spotlessApply Spotless enforces google-java-format and rejects wildcard imports. Fix formatting first so you don't re-run tests after a reformat. 2. Run the tests you changed ```shell ./gradlew :dd-trace-core:test --tests
    • Candidate answer: Here's what I'd run, in this order. It's based on AGENTS.md, CONTRIBUTING.md, docs/how_to_test.md and dd-trace-core/build.gradle. I haven't run any of it. ### 1. Format shell ./gradlew spotlessApply ./gradlew spotlessCheck Spotless applies google-java-format and fails the build on wildcard imports.

Results

  • Pairwise win-rate: 47% [44%–50%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 81.1 → 81.6 (/100, +0.5)
  • Bad signals introduced (advisory): 1
  • Candidate criteria coverage (advisory): 24/27 (89%) — expected_criteria the candidate met; does not affect the gate
  • Candidate bad signals (all, advisory): 1 case(s) — trips on the candidate, including ones the baseline also hit
  • Blocking-case regressions: 0

Cases

Case Mode Quality Δ Win-rate (90% CI) Safety
java-core-validation-001 🟡 warn -1.7 33% [16%–51%] ⚠️ bad signal
java-unit-test-conventions-001 warn 0.0 50% [50%–50%] ok
java-premain-safety-001 warn -1.1 50% [50%–50%] ok
java-ci-download-guidance-001 warn +3.3 50% [50%–50%] ok
java-documentation-only-validation-001 warn +1.7 50% [50%–50%] ok
java-existing-spock-maintenance-001 warn +0.8 50% [50%–50%] ok

Per-dimension scores, token usage, latency, and estimated cost are in the CI job logs.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 94.12%
• Overall Coverage: 60.81% (+0.02%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 20, 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.02 s 14.02 s [-0.8%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.95 s 12.99 s [-1.1%; +0.4%] (no difference)
startup:petclinic:appsec:Agent 16.54 s 17.12 s [-7.5%; +0.7%] (no difference)
startup:petclinic:iast:Agent 17.06 s 17.08 s [-1.1%; +0.9%] (no difference)
startup:petclinic:profiling:Agent 16.81 s 16.92 s [-1.6%; +0.4%] (no difference)
startup:petclinic:sca:Agent 17.14 s 16.97 s [+0.1%; +1.9%] (maybe worse)
startup:petclinic:tracing:Agent 16.17 s 16.31 s [-1.6%; -0.2%] (maybe better)

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

@dougqh
dougqh force-pushed the dougqh/toolbox-hash-spread branch from 0f0e032 to 225288e Compare November 20, 2026 20:50
@dougqh
dougqh force-pushed the dougqh/toolbox-string-canonicalizer branch from 401cf0b to f4bf924 Compare November 20, 2026 20:51
@dougqh
dougqh marked this pull request as ready for review November 20, 2026 20:56
@dougqh
dougqh requested a review from a team as a code owner November 20, 2026 20:56
@dougqh
dougqh requested review from bric3 and removed request for a team November 20, 2026 20:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-20T20:59:31.679894Z f4bf924 Draft marked ready
ℹ️ 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-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

The completed static review found no actionable defect in the bounded canonicalization logic. Parser adoption is deferred, and timing and allocation benefits remain unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f4bf924

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

Length and probe-limit fallbacks preserve text equality while allowing sharing to stop. Parser adoption is deferred, so integration behavior and performance remain unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit b6eda3e

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

Length and probe limits sacrifice sharing while preserving the returned text. The utility is not yet adopted by parsers, so this change does not alter existing parsing behavior.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit ef3a5a2

Shares one String per distinct text within one parse, from a parser's
char buffer or from strings, so long-lived parsed state keeps a single
copy of each repeated key, id or value. Sharing is per instance, never
JVM-wide, because parsed texts can be customer data.

Generalized from dd-openfeature's version (#13553) with the review fixes
built in: the hashSpread multiply instead of h ^ (h >>> 16), a bound on
equal-hash comparisons so input built from colliding strings can't make
each lookup compare against all the others, and a length limit above
which texts are neither hashed nor shared.

StringCanonicalizerBenchmark compares it with plain new String, a HashMap
interner and the original version, over generated keys, random ids and
colliding strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/toolbox-hash-spread branch from fc4cd13 to 10d466d Compare November 21, 2026 03:53
@dougqh
dougqh force-pushed the dougqh/toolbox-string-canonicalizer branch from ef3a5a2 to d7001a0 Compare November 21, 2026 03:53

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot 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.

Bits Code Review: PASS

More details

The length and probe limits preserve text equality when sharing is skipped, with no actionable defects reported by the static reviewer. Parser adoption is deferred, so integration behavior remains unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d7001a0

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: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant