Repository navigation
Conversation
LLM ValidationLLM Validation Gate — java-agent-instructions✅ PASS
6 case(s) · quality 81.4 → 80.6 (-0.8) · win-rate 50% [50%–50%] Details — analysis and per-case resultsAnalysisChanged instruction file(s): No safety or blocking-case regressions across 6 case(s). Overall pairwise win-rate 50% [50%–50%], quality -0.8 — see the verdict above for whether that clears the noise band. Results
Cases
Per-dimension scores, token usage, latency, and estimated cost are in the CI job logs. |
🟢 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. |
0f0e032 to
225288e
Compare
401cf0b to
f4bf924
Compare
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.
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.
🤖 Bits Code Review · Commit f4bf924
f4bf924 to
b6eda3e
Compare
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit b6eda3e
94db48f to
fc4cd13
Compare
b6eda3e to
ef3a5a2
Compare
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit ef3a5a2
fc4cd13 to
10d466d
Compare
ef3a5a2 to
d7001a0
Compare
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit d7001a0
10d466d to
74dd6ff
Compare
There was a problem hiding this comment.
More details
Long-string and probe-limit fallbacks preserve text equality while foregoing sharing. Validation was static; tests and benchmarks were not executed.
🤖 Bits Code Review · Commit d7001a0
798a067 to
e00c959
Compare
There was a problem hiding this comment.
More details
The length and probe limits preserve returned text when sharing is skipped. The completed source review identified no actionable defects; runtime behavior and performance remain unvalidated.
🤖 Bits Code Review · Commit e00c959
| if (oldStrings[i] != null) { | ||
| // Rehashing places every entry: the table is at most half full, so a slot is near. | ||
| int slot = HashingUtils.hashSpread(oldHashes[i]) & mask; | ||
| while (strings[slot] != null) { |
There was a problem hiding this comment.
The lookup probe limits do not cover this loop. An insertion triggers grow() synchronously, and a long occupied run in the new table can make rehashing probe many slots for each entry. Could we give rehashing a separate work budget and stop adding entries if that budget is exhausted? This would bound the extra probe work on calls that trigger growth.
--- found by Codex
There was a problem hiding this comment.
Good catch. Rather than a separate budget, rehashing now stops where a lookup would: each entry gets MAX_PROBES slots, and one with no free slot that close is dropped, which, like a lookup that gives up, only costs sharing it. So the insert that triggers growth costs at most MAX_PROBES per entry. In practice it shouldn't trigger: every entry already sat within MAX_PROBES of its slot before doubling, and the new table is a quarter full. So it's a backstop, not a path I could construct a test for. (e1397a3)
| private String insert(final int slot, final int hash, final String text) { | ||
| strings[slot] = text; | ||
| hashes[slot] = hash; | ||
| if (++size * 2 > strings.length) { |
There was a problem hiding this comment.
The length and probe limits still allow the table to grow with the number of distinct short values in a document. It holds those strings until the parse ends, including any values the parser has already discarded, and both generations of the arrays are live during growth. Could we set a per-parse entry or memory budget before wiring this up to parsers? At capacity, existing hits could still be reused and misses could return the text without adding it to the table.
--- found by Codex
There was a problem hiding this comment.
Added maxEntries, defaulting to 64K, which caps the table at about 1 MB of arrays, well above the FFE scale suite's 10K distinct values. At the cap, existing hits are still shared and misses return the text without adding it, as you suggested. Parsers can pass a tighter cap. (cede691)
| if (length > maxLength) { | ||
| return new String(chars, offset, length); | ||
| } | ||
| int hash = 0; // String.hashCode's polynomial, so canonical(String) finds the same entries |
There was a problem hiding this comment.
Could we validate the slice before probing? I checked on JDK 21 that canonical(new char[0], 1, 0) throws on an empty table and returns an empty string after a valid empty slice has been cached. A zero-length hit never reads the array, so it skips the validation performed by the String constructor on a miss. A small test covering both table states would pin down the expected behavior.
--- found by Codex
There was a problem hiding this comment.
Fixed. The range is now checked up front, so the same call throws regardless of what the table holds. There's a test covering both table states, plus the overflow case. (6aad01d)
AlexeyKuznetsov-DD
left a comment
There was a problem hiding this comment.
Very creative optimization. Left couple of findings by Codex.
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>
A hit never copies the characters, so an empty hit accepted any offset and the same call threw or not depending on what the table held. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Growth happens inside the insert that triggers it, and its probes had no limit. Each entry now gets MAX_PROBES slots, like a lookup; one with no free slot that close is dropped, which only costs sharing it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The table holds every shared text until the parse ends, including values the parser has already discarded. Past maxEntries (64K by default, about 1 MB of arrays), texts already shared still are and new ones are returned unshared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
String.format uses the default locale, which forbiddenApis rejects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
948fad7 to
c524b93
Compare
|
@AlexeyKuznetsov-DD Heads-up: I've moved this PR off #13531 onto master, so it doesn't wait on the module-layout discussion there. The code is unchanged; |
There was a problem hiding this comment.
More details
The supplied revision addresses the earlier concerns about unbounded table growth, unbounded rehash probing, and cache-dependent slice validation. The completed static review returned no reportable findings.
🤖 Bits Code Review · Commit c524b93
bric3
left a comment
There was a problem hiding this comment.
The bounded, per-instance approach looks good to me. I left a few small comments, mainly to verify the collision limit in both overloads and make the benchmark trade-offs easier to read. Happy to approve once those are addressed.
I also went ahead and renamed the PR title, and reworded a bit the description, as I was lot in the details. In particular I highlighted the massive improvement on the collision.
| * <li><b>Entries:</b> at most {@code maxEntries} texts are shared. The table holds each one until | ||
| * the parse ends, including values the parser has already discarded, so without this bound a | ||
| * document of many distinct short values would grow it without limit. Once full, texts | ||
| * already shared still are; new ones are returned unshared. |
There was a problem hiding this comment.
issue: The Javadocs promise sharing for the whole parse, but grow() can drop a cached entry when reinsertion reaches MAX_PROBES. Both canonical overloads also skip insertion at maxEntries, even when the lookup finds a free slot. Could we describe sharing as best effort, document the entry cap in both overloads, and describe size() as the current entry count? The String overload returns the original argument whenever it skips sharing, so the constructor and probe-limit docs can say "returned unshared".
There was a problem hiding this comment.
Right, the growth bound I added made that promise untrue. Fixed in 5338a44: the class doc now calls sharing best effort (a bound can return a text unshared, and growth can drop an entry), both overloads list the entry cap among the unshared cases, the constructors and probe bullet say "returned unshared", and size() is the number of texts the table holds now.
| strings.canonical(shared.toCharArray(), 0, shared.length()), | ||
| strings.canonical(shared.toCharArray(), 0, shared.length())); | ||
| final String late = colliding.get(colliding.size() - 1); | ||
| assertTrue(late.equals(strings.canonical(late))); |
There was a problem hiding this comment.
issue: This assertion would still pass if canonical(String) ignored the equal-hash limit and retained late as a 17th entry. Both overloads carry their own probe loop. Could we assert the size after the String call as well? If we keep the loops specialised, independent assertions will catch changes to either one.
| assertTrue(late.equals(strings.canonical(late))); | |
| assertTrue(late.equals(strings.canonical(late))); | |
| assertEquals(StringCanonicalizer.MAX_EQUAL_HASH_PROBES, strings.size()); |
There was a problem hiding this comment.
Added in 5338a44, with a note that canonical(String) has its own loop.
| * <li>{@code newString}: one {@code String} per token, as a parser does without sharing. The | ||
| * baseline for time; it retains a copy of every repeat. | ||
| * <li>{@code canonicalizer}: {@link StringCanonicalizer#canonical(char[], int, int)}, which | ||
| * allocates only on the first occurrence of a text. |
There was a problem hiding this comment.
suggestion: newString passes each result to the blackhole, so this arm measures time and allocation without keeping a parsed result. The canonicalizer also allocates when a repeat hits the probe limit. How about describing what each arm measures?
| * <li>{@code newString}: one {@code String} per token, as a parser does without sharing. The | |
| * baseline for time; it retains a copy of every repeat. | |
| * <li>{@code canonicalizer}: {@link StringCanonicalizer#canonical(char[], int, int)}, which | |
| * allocates only on the first occurrence of a text. | |
| * <li>{@code newString}: the time and allocation baseline, creating a {@code String} per token. | |
| * <li>{@code canonicalizer}: {@link StringCanonicalizer#canonical(char[], int, int)}, which | |
| * allocates on a miss and reuses cached instances on a hit. |
| for (int i = 0; i < 10_000; i++) { | ||
| firsts.add(strings.canonical(String.format("scale-bulk-%05d", i).toCharArray(), 0, 16)); | ||
| } | ||
| assertEquals(10_000, strings.size()); | ||
| for (int i = 0; i < 10_000; i++) { | ||
| assertSame(firsts.get(i), strings.canonical(String.format("scale-bulk-%05d", i))); | ||
| } |
There was a problem hiding this comment.
suggestion: The default format locale can change the fixture's digits and the hash distribution this test exercises. The 16 also depends on the key format. How about using Strings.format as the benchmark does, and passing the actual buffer length?
| for (int i = 0; i < 10_000; i++) { | |
| firsts.add(strings.canonical(String.format("scale-bulk-%05d", i).toCharArray(), 0, 16)); | |
| } | |
| assertEquals(10_000, strings.size()); | |
| for (int i = 0; i < 10_000; i++) { | |
| assertSame(firsts.get(i), strings.canonical(String.format("scale-bulk-%05d", i))); | |
| } | |
| final int keyCount = 10_000; | |
| final String keyPattern = "scale-bulk-%05d"; | |
| for (int i = 0; i < keyCount; i++) { | |
| final char[] key = Strings.format(keyPattern, i).toCharArray(); | |
| firsts.add(strings.canonical(key, 0, key.length)); | |
| } | |
| assertEquals(keyCount, strings.size()); | |
| for (int i = 0; i < keyCount; i++) { | |
| assertSame(firsts.get(i), strings.canonical(Strings.format(keyPattern, i))); | |
| } |
There was a problem hiding this comment.
Applied in 5338a44: Strings.format, and the real buffer length instead of 16.
| hash = 31 * hash + chars[offset + i]; | ||
| } | ||
| final int mask = strings.length - 1; | ||
| int slot = HashingUtils.hashSpread(hash) & mask; |
There was a problem hiding this comment.
nitpick: Could we static-import hashSpread for both lookup paths and grow(), as the contribution guide suggests for repeated call-style helpers?
There was a problem hiding this comment.
Done in 5338a44, for both lookups and grow().
| * | ||
| * @return the number of shared instances. | ||
| */ | ||
| public int size() { |
There was a problem hiding this comment.
suggestion: size() and MAX_EQUAL_HASH_PROBES only serve the test here. Could we keep size() package-private and mark both @VisibleForTesting? MAX_PROBES can be private.
There was a problem hiding this comment.
Done in 5338a44: size() is package-private and @VisibleForTesting, as is MAX_EQUAL_HASH_PROBES, and MAX_PROBES is private.
…probe loops Growth can drop an entry and the entry cap skips inserts even with a free slot, so the docs no longer promise sharing for the whole parse, and the String overload says it returns the text unshared. The equal-hash test checks canonical(String)'s loop too; the growth test formats with Strings.format and the real key length. size() and MAX_EQUAL_HASH_PROBES are test-only, MAX_PROBES private, and hashSpread is static-imported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What Does This Do
Adds
datadog.trace.util.StringCanonicalizertocomponents/toolbox. It shares oneStringinstance 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:
maxLength(default 128) are neither hashed nor shared.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
scaleflag 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:
HashingUtils.hashSpread(Spread StringIndex hashes so sequential names don't cluster (FFE optimization) #13576) instead ofh ^ (h >>> 16), which clusters generated keys likescale-bulk-NNNNNunder linear probing.Aa/BBblocks). With Share equal strings within a parsed feature flag configuration (FFE optimization) #13553's unbounded probing, input made of them compares each lookup against all the others, which is quadratic per parse. The bound caps that at 16 comparisons per lookup.scale-json(the other two are the spread and, in the parser, not canonicalizing JSON field names). Long values rarely repeat, so hashing them buys little. How much of the +23% it recovers is unmeasured, since that needs the dd-openfeature adoption.Each canonicalizer owns its string table. Using one instance per parse keeps sharing of customer data, such as targeting IDs, scoped to that parse.
Benchmark results per token. Each cell shows time in ns (median across forks, with the range in brackets), followed by allocation in bytes. Lower is better for both. Each distinct text appears four times.
newStringcanonicalizerhashMaporiginal(#13553)newStringand takes 4-8x as long per token. Compared withhashMap, it allocates 60-70% fewer bytes and takes between 9% less and 16% more time.originalat 1k distinct strings and 390x at 10k. Most lookups reach the probe limit and return an unshared string, so allocation is about the same asnewString.original, with enough variation across forks to leave the improvement uncertain. The ID medians are close.Setup.
StringCanonicalizerBenchmarkon Bits with JDK 21, four threads, three forks per variant, 3 x 5 s warmup, 5 x 5 s measurement, and-prof gc. Median CPU steal was 0.3%. These runs predate the current 32-bit hash spread from #13576.Additional Notes
hashSpread), which is stacked on Extract the perf toolbox into a dependency-free components/toolbox module (FFE optimization) #13531 (the toolbox module).MembershipIndex.StringTable(a second hand-written string table with the same clustering), is a follow-up, so Share equal strings within a parsed feature flag configuration (FFE optimization) #13553 doesn't depend on the toolbox stack.intcomparison. The 256-slot bound is only a backstop.FlatHashtableentries: this keeps the table to two arrays, with no extra object per distinct text during a parse.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issue🤖 Generated with Claude Code