Skip to content

Store feature flag configuration lists and maps at their exact size (FFE optimization) - #13556

Draft
dougqh wants to merge 3 commits into
masterfrom
dougqh/ffe-config-compact-collections
Draft

dougqh wants to merge 3 commits into
masterfrom
dougqh/ffe-config-compact-collections

Conversation

@dougqh

@dougqh dougqh commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Does This Do

A parsed feature flag configuration now stores its lists and maps at their exact size:

  • Every list, including ONE_OF and other list operands, is a CompactList: one shared empty list, a single object for one element, and that object plus one exact-size array for more. Elements may be null; the list is immutable.
  • The flags, variations and extraLogging maps are Map.copyOf maps, unless they hold a null key or value (a JSON null variant), which Map.copyOf rejects.

Map.copyOf maps reject null lookups, so FlagEvaluator now checks for a null flag key or variation key before looking it up. A null flag key still reads FLAG_NOT_FOUND, and a split without a variation key still reads "Variant not found". Without the checks, both would have become a GENERAL error; two new tests fail without them.

Motivation

A parsed configuration stays in the old generation until the next one replaces it, and every marking cycle walks it. In the 10,030-flag scale configuration, 33,557 of its 106,659 lists were empty and 61,409 held one element, each an ArrayList plus its array. Every flag also carried a HashMap of variations with its table and nodes.

Measured on its own by Bits: this PR's head (a375fcccb3) merged locally onto master 62d4d1a14e, as for #13553, against master 62d4d1a14e. 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 → 151,752 B (−16.9%) 5,879 → 4,863 (−17.3%) 881,448 → 919,673 B (+4.3%)
scale (10,030 flags) 27,446,320 → 23,269,040 B (−4.18 MB, −15.2%) 807,489 → 679,044 (−15.9%) 97.50 → 102.18 MB (+4.8%)
scale-json 39,392,256 → 39,389,464 B (unchanged) +2,272 B
regex suite 60,992 → 49,920 B (−18.2%) 1,876 → 1,549 (−17.4%)
  • The 24-byte CompactList (no size field) saves another 584,824 B on scale compared with the previous head.
  • scale-json doesn't move: all of it sits under Variant.value, in JSON maps and lists that aren't compacted. Compacting JSON values is a separate follow-up.
  • With Share equal strings within a parsed feature flag configuration (FFE optimization) #13553 (equal strings shared), the two together take scale to 17,128,816 B and 437,384 objects (−37.6%, −45.8%), and canonical to 104,728 B and 3,256 objects (−42.6%, −44.6%).
  • A parse allocates about 4.7 MB more for the compact copies. Parse time is within noise (scale 125 → 120 ms, scale-json 56.7 → 57.6 ms, 4 forks). Parsing only happens when the configuration changes.

ScaleSuiteBenchmark (3 forks, 7 where a case moved; base and PR alternating; the sandbox had 6–21% hypervisor steal time, so small time deltas are unconfirmed):

Case Time per evaluation
variations 50.27 → 42.71 µs (−15%)
one-of-small-numbers +8.9% (overlapping forks)
rules-sweep +2.4% (noise, 7 forks)
flags, numeric, one-of, one-of-many, regex, regex-many, rules, semver, splits, wide-context, json-*, regex/literals noise
  • The time-windows regression in this run came from CompactList inheriting AbstractList's iterator; it's fixed below.

Additional Notes

  • Why one list class. The evaluator iterates model lists with for-each loops. With one receiver class, the JIT inlines iterator() and escape analysis removes the iterator. A first version mixed emptyList, singletonList and ArrayList: same footprint, but the loops became megamorphic and allocated iterators again, about +1.5 KB per evaluation on scale/splits and +450 B on scale/rules. List.copyOf's two classes still left the splits regression. Arrays.asList fixed allocation but costs two objects per list. CompactList gives both: one class and one object for 0–1 elements.
  • Iteration order: Map.copyOf's order changes from one JVM run to the next. Nothing iterates these maps in order. The only iteration, validateNumericVariants, gives the same error whichever variant comes first.
  • Immutability: nothing mutates the model's lists or maps. Features and destinations stay immutable, as before.
  • Tests:
    • CompactListTest covers sizes 0–5, null elements, bounds, equality with ArrayList, immutability and the shared empty list.
    • UniversalFlagConfigParserTest checks the shapes (one list class, immutable maps), a JSON null variant, and null elements in ONE_OF lists.
    • FlagEvaluatorTest covers the two null lookups on parsed maps.
    • All dd-openfeature tests pass; Spotless and SpotBugs pass.
  • Independent of Leo's open PRs; the two FlagEvaluator lines are away from the code they change.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

Review follow-ups

  • The time-windows regression is fixed (5f3003e). CompactList has its own iterator instead of inheriting AbstractList's, and overrides forEach and isEmpty. AbstractList's iterator is shared by every AbstractList subclass, so in an application its size() and get() calls are megamorphic (PrintInlining shows them as virtual calls) and escape analysis keeps the iterator. iterator() returns a new iterator on every path, the empty list included, because a shared one would be a merged allocation that escape analysis can't remove.

    Re-measured by Bits with the shared list internals' profile polluted first, as in an application (ScaleSuiteBenchmark, each variant merged onto master 62d4d1a14e, 5 forks per variant rotated, 4 threads, JDK 21):

    Case master Inherited iterator (previous head) Own iterator (this head)
    time-windows 1,148 ns [1,068–1,222], 368 B 3,151 ns (+174%), 528 B 1,097 ns (noise), 368 B
    rules 3,687 ns [3,660–3,923] 4,741 ns (+29%), +349 B 3,642 ns (noise), same bytes
    one-of-small-numbers 348 ns [320–377], 380 B 421 ns (+21%), 508 B 356 ns (noise), 380 B
    variations 65.0 µs [61.2–66.6], 28,067 B 85.9 µs (+32%), 94,307 B 52.0 µs [50.8–54.4] (−20%), 28,067 B

    Bytes per evaluation match master's in every case (rules is bimodal from fork to fork in every variant, 1,622 or 2,406 B, a JIT outcome unrelated to the list). variations is 20% faster than master, with no fork overlap.

  • CompactList derives its size from its array instead of storing it: a list is 24 bytes instead of 32 with compressed oops. Footprint numbers above predate this, so the real saving is slightly larger.

  • The new idle-poll test in FlagEvaluationPipelineTest fixes a timing-dependent coverage gap: runDutyCycle's empty-poll branch was only reached when a test happened to sit idle for 100 ms, and this branch's timing tipped it under the 0.9 threshold.

🤖 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-6

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

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 98.00%
• Overall Coverage: 83.38% (+22.43%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9ebbc1f | 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.18 s 14.11 s [-0.6%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 13.03 s 13.09 s [-1.1%; +0.3%] (no difference)
startup:petclinic:appsec:Agent 17.75 s 17.54 s [+0.4%; +2.0%] (maybe worse)
startup:petclinic:iast:Agent 17.56 s 17.74 s [-2.0%; -0.1%] (maybe better)
startup:petclinic:profiling:Agent 17.49 s 17.38 s [-0.4%; +1.6%] (no difference)
startup:petclinic:sca:Agent 17.80 s 17.66 s [-0.2%; +1.8%] (no difference)
startup:petclinic:tracing:Agent 16.75 s 16.35 s [-1.9%; +6.8%] (no difference)

Commit: 9ebbc1fe · 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 Store feature flag configuration lists and maps at their exact size Store feature flag configuration lists and maps at their exact size (FFE optimization) Nov 19, 2026
dougqh and others added 3 commits November 20, 2026 20:33
A parsed configuration stays in the old generation until the next one replaces it, and every
marking cycle walks it. Most of its lists hold zero or one element, the JSON reader's lists keep
their growth slack, and every flag carried a HashMap of variations with its table and nodes.

The parser now stores:
- every list, including ONE_OF and other list operands, as a CompactList: one shared empty list,
  a single object for one element, and the object plus one exact-size array for more
- the flags, variations and extraLogging maps as Map.copyOf maps, unless they hold a null key
  or value (a JSON null variant), which Map.copyOf rejects

Every parsed list is the same class on purpose. The evaluator iterates model lists with for-each
loops: with one receiver class the JIT inlines iterator() and escape analysis removes the
iterator. Mixing emptyList, singletonList and ArrayList brought the iterators back, about 1.5 KB
per evaluation on the scale splits suite.

Map.copyOf maps reject null lookups, so FlagEvaluator checks for a null flag key or variation
key before looking it up. A null flag key still reads FLAG_NOT_FOUND, and a split without a
variation key still reads "Variant not found". Nothing iterates these maps in order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the int field, a list is 24 bytes instead of 32 with compressed oops
(AbstractList already carries modCount). Map.copyOf already returns the
shared empty map, so compactMap needs no empty case of its own.

Add a test that idles the flag-evaluation worker past its poll timeout, so
the empty-poll branch is covered regardless of test timing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AbstractList's iterator is shared by every AbstractList subclass, so its
size(), get() and modCount calls see every list class in the application.
Once that profile is polluted they aren't inlined, escape analysis keeps
the iterator, and every for-each over a configuration list allocates:
+160 B to +66 KB per evaluation and up to 3.3x slower in Bits' runs.

CompactList now has its own iterator, a plain index with no modCount since
the list is immutable, and overrides forEach and isEmpty. iterator()
returns a new iterator on every path, the empty list included, since a
shared one on any path would be a merged allocation escape analysis can't
remove. get() reads the array once.

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