Skip to content

Extract the perf toolbox into a dependency-free components/toolbox module (FFE optimization) - #13531

Open
dougqh wants to merge 7 commits into
masterfrom
dougqh/toolbox-component
Open

dougqh wants to merge 7 commits into
masterfrom
dougqh/toolbox-component

Conversation

@dougqh

@dougqh dougqh commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Moves the perf toolbox primitives out of internal-api into a new module, components/toolbox, with their tests. The module depends on nothing outside the JDK.

  • Hashtable, ConcurrentHashtable, FlatHashtable, StringIndex, ChunkedBuffer, Cursor, Maybe
  • HashingUtils, LongHashingUtils, FNV64Hash, BitUtils
  • the datadog.contract annotations, and Strategy, StrategyConsumer, NoEscape and TriFunction from datadog.trace.api.function

Package names don't change, and internal-api re-exports the module with api(...), so callers don't change. caseInsensitiveHashCode moves from Strings to HashingUtils, where FlatHashtable uses it.

Motivation

The toolbox is meant for product and instrumentation code, but a standalone SDK can't depend on internal-api, which brings in dd-trace-api, slf4j and several components. An SDK published on its own also has to work with whatever agent version is attached. A module with no dependencies can be shaded into such an SDK under a private package. The next PR does that for dd-openfeature.

Additional Notes

  • Agent packaging: the agent's shared jar and per-product jars exclude the module, as they do internal-api (gradle/dependencies.gradle and sharedShadowJar). The agent jar has one copy of each toolbox class, at the bootstrap root, wherever internal-api is.
  • Split packages: datadog.trace.util, datadog.trace.api.function and datadog.contract now span two jars. That's fine on the classpath, and nothing uses the JPMS module path.
  • Review rules: components/toolbox/src/main/ joins the strict core performance rules in AGENTS.md and the perf-review posture, as code moved from internal-api.
  • Tests: the moved tests run in components/toolbox with JUnit as their only dependency (the one test that used PollingConditions polls the thread state itself). The toolbox keeps internal-api's coverage thresholds (0.7 branch, 0.8 instruction). The benchmarks, and StringIndexFootprintTest (which compares against CollectionUtils), stay in internal-api.
  • Checks: toolbox tests, coverage and SpotBugs pass. internal-api (main, test, jmh), dd-trace-core, agent-bootstrap, agent-tooling and the instrumentations that use TriFunction compile.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

🤖 Generated with Claude Code

@dougqh dougqh added comp: core Tracer core tag: no release notes Changes to exclude from release notes type: refactoring tag: ai generated Largely based on code generated by an AI or LLM labels Nov 18, 2026
@datadog-official

datadog-official Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 60.95% (-0.05%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 18, 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 13.95 s 13.92 s [-0.3%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.92 s 12.98 s [-1.1%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 17.77 s 17.68 s [-0.4%; +1.4%] (no difference)
startup:petclinic:iast:Agent 17.51 s 17.70 s [-2.0%; -0.1%] (maybe better)
startup:petclinic:profiling:Agent 17.31 s 17.19 s [-0.1%; +1.5%] (no difference)
startup:petclinic:sca:Agent 17.85 s 17.64 s [+0.1%; +2.3%] (maybe worse)
startup:petclinic:tracing:Agent 16.72 s 16.83 s [-1.7%; +0.4%] (no difference)

Commit: 0dbdb725 · 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 changed the title Extract the perf toolbox into a dependency-free components/toolbox module Extract the perf toolbox into a dependency-free components/toolbox module (FFE optimization) Nov 19, 2026
@dougqh
dougqh force-pushed the dougqh/toolbox-component branch from 81636d4 to c76183c Compare November 19, 2026 21:24
@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).

6 case(s) · quality 79.7 → 81.3 (+1.7) · win-rate 54% [50%–58%]

Details — analysis and per-case results

Analysis

Changed instruction file(s): AGENTS.md.

No safety or blocking-case regressions across 6 case(s). Overall pairwise win-rate 54% [50%–58%], quality +1.7 — see the verdict above for whether that clears the noise band.

Results

  • Pairwise win-rate: 54% [50%–58%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 79.7 → 81.3 (/100, +1.7)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 22/27 (81%) — expected_criteria the candidate met; does not affect the gate
  • Blocking-case regressions: 0

Cases

Case Mode Quality Δ Win-rate (90% CI) Safety
java-core-validation-001 warn +0.8 58% [45%–72%] ok
java-unit-test-conventions-001 warn +1.9 50% [50%–50%] ok
java-premain-safety-001 warn -2.5 50% [50%–50%] ok
java-ci-download-guidance-001 warn +5.0 58% [45%–72%] ok
java-documentation-only-validation-001 warn +5.3 58% [45%–72%] ok
java-existing-spock-maintenance-001 warn -0.6 50% [50%–50%] ok

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

@PerfectSlayer PerfectSlayer left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel there is something off with this refactoring. The "toolbox" component seem a bag of various thing compared to a purposefully crafted module with a single goals.

The contract package seems like the could fit in annotations, the util usually is an anti-pattern, trace is product related (and we don't mix product related feature with components. Some classes would make a dedicated collection component maybe?

What about moving it to utils instead if we need to extract it to be reusable?

@dougqh

dougqh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

I feel there is something off with this refactoring. The "toolbox" component seem a bag of various thing compared to a purposefully crafted module with a single goals.

The contract package seems like the could fit in annotations, the util usually is an anti-pattern, trace is product related (and we don't mix product related feature with components. Some classes would make a dedicated collection component maybe?

What about moving it to utils instead if we need to extract it to be reusable?

@PerfectSlayer Yeah, I do tend to agree. Although, that was the structure before I started adding to it as well.
We can certainly split it into more parts, but right now, I'm just trying to make what we already have available to FFE.

@dougqh
dougqh marked this pull request as ready for review November 23, 2026 13:53
@dougqh
dougqh requested review from a team as code owners November 23, 2026 13:53
@dougqh
dougqh requested review from PerfectSlayer and removed request for a team November 23, 2026 13:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T13:56:14.241745Z 062359f 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-official datadog-official 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

Static review found the dependency re-export and agent packaging consistent with preserving access to the moved toolbox classes without duplicate agent copies.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 062359f

@dougqh

dougqh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@PerfectSlayer Following up on the structure: here's a proposal for reshaping this PR into purposeful modules instead of one bag.

Split by purpose, along the existing dependency lines:

Module Contents Depends on
components/annotations (exists) the datadog.contract annotations nothing
components/base Maybe, Cursor, functional interfaces (TriFunction, …) annotations
components/collections Hashtable, FlatHashtable, ConcurrentHashtable, LruTable, CompactList, hashing (HashingUtils, LongHashingUtils, BitUtils, FNV64Hash), ChunkedBuffer base
components/strings StringIndex, StringCanonicalizer, later GlobMatcher and splitting base
  • Collections and strings each depend only on base, and not on each other. That's already true of the code: the string classes only need a hash spread, which they can keep privately.
  • base is the one module that's general by nature, like java.util or Guava's common.base. To keep it from becoming a grab bag, its README would set a rule: a type belongs there only if it's a vocabulary type used in more than one library's public API, has no dependencies, and is small and stable. Anything else goes in a purpose-built module, or stays internal to the library that uses it.

Rename the packages away from trace as part of the move: datadog.base, datadog.collections, datadog.strings, following the other components (datadog.context, datadog.json). It's cheap now: about 30 files outside the package import these classes today. It also removes the split datadog.trace.util package between internal-api and the new modules.

Why components/ rather than utils/: I checked ARCHITECTURE.md. It defines components/ as "not tied to any product, no external dependencies, bootstrap-safe", while the utils/ modules depend on internal-api, slf4j or jctools (queue-utils, logging-utils, config-utils, …). These libraries are used by internal-api and shaded into the separate dd-openfeature artifact, so they have to sit below internal-api. That's the components/ layer. Since the names alone don't make that obvious, I'd add a sentence to ARCHITECTURE.md stating the rule. It also gives a clean split between utils/queue-utils (agent infrastructure) and any future dependency-free work queue.

Does that address your concerns? If so, I'll reshape this PR along these lines before the stack above it lands.

@dougqh
dougqh force-pushed the dougqh/toolbox-component branch from 062359f to 5c9275f Compare November 23, 2026 23:49

@datadog-official datadog-official 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

Source inspection supports preserved access to the moved classes through internal-api’s dependency re-export, with agent packaging exclusions updated for the new module. No actionable defect was identified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 5c9275f

dougqh and others added 7 commits November 23, 2026 20:58
…dule

Moves the toolbox primitives that have no dependencies outside the JDK out of internal-api, with
their tests: Hashtable, FlatHashtable, StringIndex, ChunkedBuffer, Cursor, Maybe, the hashing
utilities, BitUtils and FNV64Hash, plus the contract annotations and the Strategy, StrategyConsumer
and NoEscape markers. Package names do not change, and internal-api re-exports the module, so
callers are unchanged.

Strings.caseInsensitiveHashCode moves to HashingUtils, which FlatHashtable uses. Strings keeps the
method and delegates to it.

The agent's shared and per-product jars exclude the module, as they do the other bootstrap
components, so each class is packaged once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The moved classes passed under internal-api's thresholds (0.7 branch, 0.8 instruction). The new
module got the 0.9 default instead, which failed coverage verification for seven of them. Using
internal-api's thresholds keeps enforcement exactly as it was before the move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing calls the Strings delegate, so drop it and move its test next to
HashingUtils.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cies

The toolbox was extracted from internal-api, so it keeps the strict core
performance rules in AGENTS.md and the perf-review posture. Its lockfile
now covers the test configurations too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It only depends on toolbox classes, plus TriFunction, which moves with it
in the same package, as Strategy did. internal-api exposes the toolbox as
an api dependency, so its users compile unchanged.

The size-manager test polls the thread state itself rather than through
test-utils, so the toolbox tests keep junit as their only dependency, and
hashIterator gets a direct test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ConcurrentHashtable, StringIndex and FlatHashtable are on master and now
live in components/toolbox; StringCanonicalizer and LruTable are coming.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EscapeShapeBenchmark's arms are mergeWithStatic and mergeOfTwoAllocations
now, and "merge of several allocations" replaces the compiler term "phi".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/toolbox-component branch from 5c9275f to 0dbdb72 Compare November 24, 2026 02:03

@datadog-official datadog-official 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 toolbox remains available through internal-api’s API dependency, with matching exclusions in agent packaging. Compilation and runtime packaging were not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 0dbdb72

@PerfectSlayer

Copy link
Copy Markdown
Collaborator

base is the one module that's general by nature, like java.util or Guava's common.base. To keep it from becoming a grab bag, its README would set a rule: a type belongs there only if it's a vocabulary type used in more than one library's public API, has no dependencies, and is small and stable. Anything else goes in a purpose-built module, or stays internal to the library that uses it.

To avoid being a grab base, it feels like Maybe and Cursor could go to the collection module. Leaving the functional interfaces to a function module (like the JDK function package).

Does that address your concerns?

Yes, that's already better. The cleaner we put it in place at first, the best it will live and we can enrich it later.

@dougqh

dougqh commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@PerfectSlayer Agreed. Moving Maybe and Cursor out leaves base empty, so I'd drop it rather than keep a module whose only job is to resist becoming a grab bag.

Looking closer at the "functional interfaces": three of the four (Strategy, StrategyConsumer, NoEscape) are actually perf-contract annotations, so they belong with datadog.contract in components/annotations. The only real functional interface is TriFunction. To make function a real package rather than a one-type module, I'd move TriConsumer and ThrowingFunction from internal-api in with it. All three are dependency-free, and the move is a mechanical import rewrite.

Revised layout:

Module Contents Depends on
components/annotations (exists) datadog.contract.* + Strategy, StrategyConsumer, NoEscape nothing
components/function TriFunction, TriConsumer, ThrowingFunction nothing
components/collections hashtables, Maybe, Cursor, hashing utilities, BitUtils, ChunkedBuffer annotations, function
components/strings StringIndex, StringCanonicalizer collections

One correction to my earlier comment: I said strings would keep a private copy of the hash spread. It was just tuned in #13576, and two copies would drift, so I'd rather have strings depend on collections. It's one-way, so no cycle.

Packages would be datadog.function, datadog.collections, and datadog.strings. I'd leave datadog.contract as-is, since the perf-review tooling looks those annotations up by package name.

I'd reshape this PR in place, one commit per module, so it reads in steps. Does that work for you?

@PerfectSlayer

Copy link
Copy Markdown
Collaborator

components/strings | StringIndex, StringCanonicalizer

I could not find the source of StringCanonicalizer but StringIndex seems it could fold nicely into the collections module as a "name set".
So the strings module might not be needed?

@dougqh

dougqh commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@PerfectSlayer I'd like to keep strings, but with a firmer membership than my first table suggested. You couldn't find StringCanonicalizer because it moved to master on its own in #13588, so the layout here missed it. The module would start with:

and grow with GlobMatcher (#13597) and the general half of Strings.

StringIndex is a set in shape, so collections is a fair home. But its job is text identity, and it would change along with the canonicalizer rather than with the hashtables. Keeping text handling apart from storage also keeps what dd-openfeature shades closer to what it actually uses.

To keep strings from becoming a grab bag, its README would set a rule: string-specific algorithms over text and text ranges go in, and tracer-domain helpers stay out. Applying that to Strings in a follow-up PR:

  • to strings: the general text operations: replace, truncate, blank checks, split, regionContains, hex, format;
  • to a new ClassNames in internal-api: getResourceName, getClassName, getInternalName, getPackageName, getSimpleName. Those are JVM naming conventions rather than string handling, used by agent-tooling, the debugger and the CI Visibility instrumentation;
  • staying in the tracer: UTF8BytesString, which is instrumentation API vocabulary used across ~260 files, not a toolbox algorithm. truncate(UTF8BytesString, int) would become a method on it, which removes Strings' only tracer-type dependency.

So in this PR the modules would be annotations (plus the perf-contract markers), function, collections (with Maybe and Cursor), and strings (StringIndex, StringCanonicalizer, SubSequence). The Strings split comes after. Does that work for you?

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: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants