Skip to content

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

Draft
dougqh wants to merge 1 commit into
masterfrom
dougqh/ffe-config-share-strings
Draft

dougqh wants to merge 1 commit into
masterfrom
dougqh/ffe-config-share-strings

Conversation

@dougqh

@dougqh dougqh commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

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 StringCanonicalizer (package-private, not thread-safe, dropped when the parse returns) is an open-addressing table of strings and their hashes. 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.

Measured on its own by Bits: 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

A parsed configuration stays in the old generation until the next one replaces it, and every
marking cycle walks it. The parser kept a separate String for each occurrence of a text, so
attribute names, variation keys, allocation keys, salts and ONE_OF values were repeated
thousands of times in a large configuration.

A per-parse StringCanonicalizer now returns one instance for each distinct text. String values
are canonicalized from Jackson's character buffer, so a repeated value never allocates a String,
and field names go through the same table, so a map key and the value that repeats it (the flags
key and Flag.key, a variations key, Variant.key and Split.variationKey) share one instance.

Jackson's INTERN_FIELD_NAMES is turned off: it put flag keys, variation keys and the keys of JSON
values, which are customer data, in the JVM-wide string table. Sharing stays within a parse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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: 100.00%
• Overall Coverage: 60.65% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: d633d4a | 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.12 s 14.11 s [-0.5%; +0.6%] (no difference)
startup:insecure-bank:tracing:Agent 13.00 s 13.01 s [-0.8%; +0.6%] (no difference)
startup:petclinic:appsec:Agent 17.84 s 17.69 s [-0.2%; +1.8%] (no difference)
startup:petclinic:iast:Agent 17.61 s 17.71 s [-1.6%; +0.4%] (no difference)
startup:petclinic:profiling:Agent 17.49 s 17.53 s [-1.5%; +1.1%] (no difference)
startup:petclinic:sca:Agent 17.90 s 17.83 s [-0.5%; +1.2%] (no difference)
startup:petclinic:tracing:Agent 16.77 s 16.88 s [-1.6%; +0.2%] (no difference)

Commit: d633d4a3 · 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 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>
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 21, 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