Skip to content

Introduce a reusable string canonicalizer for FFE parsing - #13588

Open
dougqh wants to merge 6 commits into
masterfrom
dougqh/toolbox-string-canonicalizer
Open

dougqh wants to merge 6 commits into
masterfrom
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:

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.

Shape, distinct texts 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
  • For repeated keys and IDs, the canonicalizer allocates 52-65% fewer bytes than newString and takes 4-8x as long per token. Compared with hashMap, it allocates 60-70% fewer bytes and takes between 9% less and 16% more time.
  • For colliding strings, the canonicalizer takes 198 ns per token at both tested sizes. That's about 42x faster than original at 1k distinct strings and 390x at 10k. Most lookups reach the probe limit and return an unshared string, so allocation is about the same as newString.
  • The key cases have median times about 10% lower than original, with enough variation across forks to leave the improvement uncertain. The ID medians are close.
  • An expected-size constructor could reduce allocation from growing the backing arrays.

Setup. StringCanonicalizerBenchmark on 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

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).

6 case(s) · quality 81.4 → 80.6 (-0.8) · win-rate 50% [50%–50%]

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 50% [50%–50%], quality -0.8 — see the verdict above for whether that clears the noise band.

Results

  • Pairwise win-rate: 50% [50%–50%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 81.4 → 80.6 (/100, -0.8)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 24/27 (89%) — 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.3 50% [50%–50%] ok
java-unit-test-conventions-001 warn +0.8 50% [50%–50%] ok
java-premain-safety-001 warn +1.9 50% [50%–50%] ok
java-ci-download-guidance-001 warn -4.7 50% [50%–50%] ok
java-documentation-only-validation-001 warn -2.8 50% [50%–50%] ok
java-existing-spock-maintenance-001 warn -0.3 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: 91.25%
• Overall Coverage: 59.65% (-1.56%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5338a44 | 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 13.95 s 13.95 s [-0.8%; +0.6%] (no difference)
startup:insecure-bank:tracing:Agent 12.91 s 12.97 s [-1.0%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 16.79 s 17.18 s [-6.5%; +1.9%] (no difference)
startup:petclinic:iast:Agent 16.70 s 17.12 s [-6.8%; +1.9%] (no difference)
startup:petclinic:profiling:Agent 16.91 s 16.91 s [-1.2%; +1.2%] (no difference)
startup:petclinic:sca:Agent 17.17 s 16.65 s [-1.2%; +7.4%] (no difference)
startup:petclinic:tracing:Agent 16.23 s 16.26 s [-1.2%; +0.9%] (no difference)

Commit: 5338a44c · 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

@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

@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

Long-string and probe-limit fallbacks preserve text equality while foregoing sharing. Validation was static; tests and benchmarks were not executed.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d7001a0

Base automatically changed from dougqh/toolbox-hash-spread to master November 23, 2026 23:34
@dougqh
dougqh force-pushed the dougqh/toolbox-string-canonicalizer branch from 798a067 to e00c959 Compare November 24, 2026 02:03

@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 returned text when sharing is skipped. The completed source review identified no actionable defects; runtime behavior and performance remain unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 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) {

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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) {

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 AlexeyKuznetsov-DD 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.

Very creative optimization. Left couple of findings by Codex.

dougqh and others added 5 commits November 24, 2026 16:46
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>
@dougqh
dougqh changed the base branch from dougqh/toolbox-component to master November 24, 2026 21:48
@dougqh
dougqh force-pushed the dougqh/toolbox-string-canonicalizer branch from 948fad7 to c524b93 Compare November 24, 2026 21:48
@dougqh
dougqh requested review from a team as code owners November 24, 2026 21:48
@dougqh
dougqh requested review from claponcet, erikayasuda, jandro996, mtoffl01 and ygree and removed request for a team November 24, 2026 21:48
@dougqh

dougqh commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@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; StringCanonicalizer and its test now sit in internal-api next to StringIndex, same datadog.trace.util package. #13531 will move it into the new module along with the rest.

@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 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.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit c524b93

@bric3 bric3 changed the title Add a bounded, per-parse StringCanonicalizer to the toolbox (FFE optimization) Introduce a reusable string canonicalizer for FFE parsing Nov 26, 2026

@bric3 bric3 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.

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.

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.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)));

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.

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.

Suggested change
assertTrue(late.equals(strings.canonical(late)));
assertTrue(late.equals(strings.canonical(late)));
assertEquals(StringCanonicalizer.MAX_EQUAL_HASH_PROBES, strings.size());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 5338a44, with a note that canonical(String) has its own loop.

Comment on lines +27 to +30
* <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.

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.

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?

Suggested change
* <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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 5338a44.

Comment on lines +73 to +79
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)));
}

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.

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?

Suggested change
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)));
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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;

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.

nitpick: Could we static-import hashSpread for both lookup paths and grow(), as the contribution guide suggests for repeated call-style helpers?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 5338a44, for both lookups and grow().

*
* @return the number of shared instances.
*/
public int size() {

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>

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.

3 participants