Skip to content

Share equal strings within a parsed feature flag configuration (FFE optimization) - #13553

Draft
dougqh wants to merge 16 commits into
dougqh/ffe-toolbox-shadingfrom
dougqh/ffe-config-share-strings
Draft

dougqh wants to merge 16 commits into
dougqh/ffe-toolbox-shadingfrom
dougqh/ffe-config-share-strings

Conversation

@dougqh

@dougqh dougqh commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

Stacked on #13532, which shades the toolbox into dd-openfeature. It merges in #13588 (the toolbox StringCanonicalizer, itself on #13576), whose commits drop out of this diff once those land. The only commit of this PR is 440016510f.

A parsed feature flag configuration now keeps one String for each distinct text, however many times the document repeats it: attribute names, variation keys, allocation keys, salts, ONE_OF values, and map keys together with the values that repeat them (the flags key and Flag.key; a variations key, Variant.key and Split.variationKey).

  • A per-parse toolbox StringCanonicalizer (Introduce a reusable string canonicalizer for FFE parsing #13588: not thread-safe, bounded, dropped when the parse returns) is an open-addressing table of strings and their hashes. This PR first shipped its own copy; it now uses the toolbox one. String values are canonicalized from Jackson's character buffer, so a repeated value never allocates a String. Field names go through the same table.
  • Jackson's INTERN_FIELD_NAMES is turned off. By default it put flag keys, variation keys and the keys of JSON values, which are customer data, in the JVM-wide string table. Field names are still canonicalized in the parser factory's own symbol table (CANONICALIZE_FIELD_NAMES stays on), which outlives a parse but is bounded in size; the StringCanonicalizer sharing of values stays within one parse.

Motivation

A parsed configuration stays in the old generation until the next one replaces it. Remote Config only delivers changes, and the CDN source skips the parse on a 304, so in production the configuration is long-lived. Every concurrent marking cycle walks it again, so each duplicate costs memory and marking work for its whole life. Duplicate strings were about a quarter of the retained configuration.

Re-measured with the toolbox StringCanonicalizer (this branch 440016510f against its base, #13532 at 676974da40; JOL, everything reachable from the ServerConfiguration; 3 identical runs each):

Configuration Retained before → after Objects
canonical ufc-config.json 184,216 → 137,192 B (−25.5%) 5,949 → 4,342 (−27.0%)
scale 27,449,168 → 21,309,168 B (−22.4%) 807,650 → 565,998 (−29.9%)
scale-json 39,392,456 → 34,204,376 B (−13.2%) 1,047,385 → 852,609 (−18.6%)

That's within 0.3 percentage points of the original version below.

Parse (5 rotated forks per build, re-run where steal was uneven): the base, this branch with the toolbox canonicalizer, and the original FFE-local canonicalizer on the same base:

suite base toolbox original
scale 97.1 ms, 97.4 MB 112.5 ms, 93.0 MB 113.5 ms, 93.3 MB
scale-json 57.3 ms, 64.6 MB 77.8 ms, 61.6 MB 77.4 ms, 61.6 MB
  • Toolbox against the original: within 1% on both suites. The move to the toolbox costs nothing.
  • Sharing against no sharing: +16% (scale) and +35% (scale-json) parse time, for 4.5% less allocation per parse and the retained savings above. In a profile, the canonicalizer is about 20% of the parse, mostly comparing a candidate against the stored string and the lookup itself. Part of the gap is steal, which stayed higher on the sharing builds (5–8% against 3%) despite reruns.
  • Where it runs: parsing happens on a background thread at configuration load, and Skip re-parsing an unchanged feature flag configuration without an ETag (FFE optimization) #13554 skips re-parsing an unchanged body.

Measured with this PR's original FFE-local canonicalizer, before it moved to the toolbox one; a re-measurement is queued. That run took this PR's head (d633d4a341) merged locally onto master 62d4d1a14e (only a test-file conflict, resolved by keeping both tests), against master 62d4d1a14e. The merge keeps #13486's MembershipIndex out of the comparison. JDK 21, compressed oops.

Footprint (JOL, everything reachable from the ServerConfiguration), and allocation per parse:

Configuration Retained before → after Objects Allocated per parse
canonical ufc-config.json (48 flags) 182,528 → 135,504 B (−25.8%) 5,879 → 4,272 (−27.3%) 881,448 → 846,281 B (−4.0%)
scale (10,030 flags) 27,446,320 → 21,306,096 B (−6.14 MB, −22.4%) 807,489 → 565,829 (−29.9%) 97.50 → 93.03 MB (−4.6%)
scale-json (10 flags, large JSON values) 39,392,256 → 34,204,176 B (−13.2%) 1,047,376 → 852,600 (−18.6%) 64.56 → 61.62 MB (−4.5%)
regex suite 60,992 → 48,328 B (−20.8%) 1,876 → 1,378 (−26.5%)

ScaleSuiteBenchmark (2 forks, alternating with master): bytes per evaluation are identical to master in every case, apart from cases where both sides flip between the same two JIT-dependent values. The sandbox had 6–21% hypervisor steal time, so time deltas under about 7% are unconfirmed.

Cases
Faster, over 7% with non-overlapping forks rules-sweep −22%, regex-many −17%, one-of-many −16%, variations −12%, numeric −12%, one-of-small-numbers −12%, json-sizes −11%, json-shapes −9.5%
Under the noise floor flags −6.7%, semver −5.4%, rules −4.7%, json-values +5.9%
Noise one-of, regex, splits, time-windows, wide-context, regex/literals

ScaleSuiteLoadBenchmark (6 forks):

Configuration Parse time Allocated per parse
scale 125 → 125 ms (noise) 97.60 → 93.14 MB (−4.6%)
scale-json 56.7 → 69.9 ms (+23%) 64.56 → 61.62 MB (−4.5%)
  • Parsing scale-json is 23% slower (+13 ms per parse; fork ranges [55.7..57.7] vs [69.2..70.8]), probably from canonicalizing its ~155k strings, most of them inside large JSON variation values. It's a load-time cost, paid when the configuration changes, not per evaluation. Skipping canonicalization inside large JSON values is a possible follow-up.
  • The evaluation speedups are larger than sharing strings alone would suggest. A plausible cause is a smaller, denser working set across 10,030 flags (fewer cache misses, and hash codes already computed), but that isn't profiled.

Additional Notes

  • With Store feature flag configuration lists and maps at their exact size (FFE optimization) #13556 (exact-size lists and maps), the two together take scale to 15.02 MB (−39%) and 435,064 objects (−46%), and canonical to 108,008 B (−40%) and 3,236 objects (−45%).

  • Not String.intern(): the texts include customer data, such as ONE_OF user ids, which shouldn't reach a JVM-wide table.

  • Field names are still canonicalized by Jackson (CANONICALIZE_FIELD_NAMES stays on); only the JVM-wide interning is off. Nothing in dd-openfeature compares field names by identity.

  • Tests:

    • StringCanonicalizerTest: sharing, the copy on a miss, equal hashes ("Aa"/"BB"), empty, non-ASCII and surrogate pairs, growth to 10,000 texts.
    • UniversalFlagConfigParserTest: assertSame for the keys listed above and for two conditions' attributes, plus escapes, non-ASCII and a 20,000-character value.
    • All dd-openfeature tests pass, including CanonicalFixtureTest and ScaleSuiteTest; Spotless and SpotBugs pass.
  • Independent of Return read-only JSON flag values with exact integers #13484 and Index ONE_OF and NOT_ONE_OF lists when the configuration loads #13486–Hash FFE shards without allocating #13490. Leo's parser PRs touch other parts of UniversalFlagConfigParser, so expect at most a small rebase. A possible follow-up seeds the table with the strings of the configuration being replaced, so a new version shares unchanged strings with the old one during the swap.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

🤖 Generated with Claude Code

@dougqh dougqh added type: feature Enhancements and improvements tag: performance Performance related changes tag: ai generated Largely based on code generated by an AI or LLM comp: openfeature OpenFeature labels Nov 19, 2026
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 95.29%
• Overall Coverage: 60.82% (+0.03%)

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

@dd-octo-sts

dd-octo-sts Bot commented Nov 19, 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.03 s 14.04 s [-0.9%; +0.8%] (no difference)
startup:insecure-bank:tracing:Agent 12.96 s 12.94 s [-0.6%; +0.8%] (no difference)
startup:petclinic:appsec:Agent 17.81 s 17.53 s [+0.7%; +2.5%] (maybe worse)
startup:petclinic:iast:Agent 17.56 s 17.07 s [-1.6%; +7.3%] (no difference)
startup:petclinic:profiling:Agent 17.40 s 16.95 s [-1.7%; +7.0%] (no difference)
startup:petclinic:sca:Agent 17.87 s 17.74 s [-0.2%; +1.6%] (no difference)
startup:petclinic:tracing:Agent 15.83 s 16.90 s [-11.9%; -0.7%] (unstable)

Commit: 44001651 · 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 Share equal strings within a parsed feature flag configuration Share equal strings within a parsed feature flag configuration (FFE optimization) Nov 19, 2026
dougqh and others added 4 commits November 19, 2026 16:10
…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>
dougqh added a commit that referenced this pull request Nov 20, 2026
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 added a commit that referenced this pull request Nov 20, 2026
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>
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>
dougqh added a commit that referenced this pull request Nov 20, 2026
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 and others added 10 commits November 20, 2026 22:52
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>
dd-openfeature is published on its own and must work with any attached agent version, so it can't
depend on the toolbox module. Instead its published jar carries a relocated copy of the toolbox
classes it uses, under com.datadog.openfeature.internal.shaded, and Shadow's minimize() drops the
classes it doesn't reach.

The Shadow plugin is not applied: publish.gradle would then list only api dependencies in the POM
and drop opentelemetry-api. A ShadowJar task replaces the jar of the java component's apiElements
and runtimeElements instead, so the publication and its POM are unchanged. The plain jar moves to
the "unbundled" classifier, and the japicmp checks compare the published jar.

checkToolboxRelocation, run by check, fails if an unrelocated toolbox class reaches the jar.

Nothing in the SDK uses the toolbox yet, so the published jar has the same entries as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compareToReferenceJar (jardiff) compares the module's jar task output unless the Shadow plugin
is applied. Here the plain jar moved to the "unbundled" classifier and toolboxJar became the
published jar, so the check looked for an unbundled jar the reference set doesn't have. It now
compares the published, shaded jar; a clean rebuild matches it byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI runs :dd-openfeature:jar and collects build/libs/*.jar, but jar now
builds the unbundled jar into build/libs-unbundled, which left nothing for
validate_build, the S3 upload or system-tests. jar is now finalized by
toolboxJar, which writes the shaded jar to build/libs.

The shaded jar also takes the plain jar's manifest, so it keeps the
Implementation-* attributes the jar convention sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StringIndex spread String.hashCode with h ^ (h >>> 16), so names that
differ only in a trailing counter landed in adjacent slots and grew long
linear-probe runs: 10,030 names like scale-bulk-NNNNN averaged 6.3 probes,
with a worst case of 156. HashingUtils.hashSpread is FlatHashtable's
golden-ratio multiply and fold, made public; StringIndex now uses it, and
the same names average 1.2 probes with a worst case of 10. FlatHashtable's
slots are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HashingUtils.hashSpread now takes an int and spreads it with a 32-bit
golden-ratio multiply folded by >>> 15. On StringIndex lookups it keeps
the 64-bit version's gain on sequential misses (-27% to -49%) while
random-key hits stay within noise of the old h ^ (h >>> 16), where the
64-bit multiply cost +4-5%. On 10,030 sequential names it averages 1.20
probes with a worst case of 10.

The 64-bit version moves to LongHashingUtils.hashSpread(long), which
FlatHashtable keeps for its composite hashes, so its slots don't change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 parsed configuration repeats the same texts many times: field names,
flag and variation keys, attribute names and condition values. Parse
each document through one toolbox StringCanonicalizer, a bounded,
per-parse table, so each distinct text is kept once. Its table is
dropped with the parse, so it never grows JVM-wide the way
String.intern()'s does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dougqh
dougqh force-pushed the dougqh/ffe-config-share-strings branch from d633d4a to 4400165 Compare November 23, 2026 14:00
@dougqh
dougqh changed the base branch from master to dougqh/ffe-toolbox-shading November 23, 2026 14:00
@pr-commenter

pr-commenter Bot commented Nov 23, 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 80.6 → 82.3 (+1.7) · win-rate 53% [50%–56%]

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

Results

  • Pairwise win-rate: 53% [50%–56%] — candidate's share of blind comparisons (90% CI; spanning 50% = no clear difference)
  • Overall quality: 80.6 → 82.3 (/100, +1.7)
  • Bad signals introduced (advisory): 0
  • Candidate criteria coverage (advisory): 23/27 (85%) — 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.6 50% [50%–50%] ok
java-unit-test-conventions-001 warn +1.1 50% [50%–50%] ok
java-premain-safety-001 warn -1.7 50% [50%–50%] ok
java-ci-download-guidance-001 warn +11.4 67% [49%–84%] ok
java-documentation-only-validation-001 warn 0.0 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.

dougqh added a commit that referenced this pull request Nov 23, 2026
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 added a commit that referenced this pull request Nov 24, 2026
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/ffe-toolbox-shading branch from 676974d to 97180eb Compare November 24, 2026 02:04
dougqh added a commit that referenced this pull request Nov 24, 2026
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>

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: openfeature OpenFeature 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