Repository navigation
Hash FFE shards without allocating - #13490
Draft
leoromanovsky wants to merge 13 commits into
Draft
leoromanovsky wants to merge 13 commits into
leoromanovsky wants to merge 13 commits into
Conversation
Add ScaleSuiteBenchmark, which evaluates each case of the opt-in scale suite of the shared FFE fixtures. The setup checks every expected value and reason first. Pin ffe-system-test-data to the scale suite PR head.
The scale benchmark sat on the JSON value change and checked JSON integers by type, so it could not set a baseline on master. It now compares JSON numbers by value, covers every case file of the scale and scale-json suites, can isolate one case with the index parameter, and prints each case's index. A load benchmark measures parsing each suite's configuration and prints the heap it retains, so changes that move work to load time show their cost. The submodule points to the scale-suite fixture branch, which adds the N x M dimensions and JSON values up to 10 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compute the shard from the first four MD5 bytes as an unsigned int, which equals parsing the first eight hex characters, with a per-thread MessageDigest and encoding buffers instead of a new digest, a hex string and a concatenated key on each call. Within one evaluation, hash each distinct salt once, so shards that share a salt across splits and allocations reuse the hash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Create one ShardHasher per evaluation instead of reusing one per thread. A nested evaluation on the same thread can no longer change another evaluation's targeting key, and a thread keeps no SDK class and no targeting key: the thread-locals hold only the MessageDigest and the encoding buffer, which is zeroed after each hash. The first salt is kept in fields, so a flag with one salt allocates no table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Contributor
🟢 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. |
The scale benchmarks failed the forbidden API check on System.out, and nothing outside a manual JMH run checked the scale cases, so a sibling change that resolves a large configuration wrongly would go unnoticed. - Add ScaleSuiteTest: evaluate every case of the scale and scale-json suites twice, and fail when the benchmark misses a case file. The cases, their check and the suite reader move to the test sources and the benchmarks reuse them; the reader uses JsonReading. - Allow System.out in the benchmark setups (@SuppressForbidden). - Check every case again after the measurement, fail on an error code, and reject expectations the check does not handle. - Rerun the jmh task when the fixtures change. - Measure retained heap after a first parse, as the smallest of three signed samples. - Describe a row as the unweighted mean over the cases of a file, say that hooks are not measured and when to run three forks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fixture PR now checks that the committed scale files match the generator and fixes its docs. The case and configuration files are unchanged, so the benchmark numbers do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fixtures add a case file with ONE_OF lists of the integers 1 to 1000 and of the powers of two up to 2^52, which an index keyed on exact doubles must still match. Pin them and benchmark the file; its 8 cases pass on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The OpenFeature client passes the provider a new LayeredEvaluationContext on each call, while the benchmark reused one MutableContext. A rule on `id` when the context has no `id` reads the layered context's key set, which it builds again on each call, so the benchmark did not show what applications pay for it. evaluateLayered wraps each case's context the way the client does, as ExperimentationOptOutBenchmark.evaluateFreshLayeredContext does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fixtures replace the 10 MB JSON flag with a 4 MB one, which brings the scale-json configuration from 14 MB down to 8 MB. The other cases are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After digest() the JDK MD5 engine still holds the last input block, which contains the targeting key, so a pooled thread kept it. Reset the digest in the same finally block that zeroes the buffer. Add tests for the buffer size of three-byte chars, for forgetting the key and not retaining large buffers, and for creating no table for one salt. Keep random totalShards within 1 to 2^32-1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from
leo.romanovsky/ffe-scale-suite-benchmark
to
master
November 19, 2026 03:09
Take master's version of every file from #13485, which merged as a squash commit, so this branch only carries the shard hashing change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Shard assignment no longer allocates for each shard. Each distinct salt is hashed once per evaluation. On
master,scale/splitsdrops from 21.2 µs and 33.5 KB to 4.6 µs and 0.8 KB per evaluation.Assignments do not change. The shard is still
int(md5("<salt>-<targetingKey>").hexdigest()[:8], 16) % totalShards, with the UTF-8 bytes thatString.getBytesproduces, so the result is the same for every salt, key andtotalShards.Motivation
We need to win a performance-sensitive customer, and the scale benchmarks of #13485 (now on
master) measure that work. Split-heavy flags were the costliest shape inscale/splits. For every shard of every split it visited, the evaluator did the following:MessageDigest.salt + "-" + targetingKey.substringof it and parsed it withLong.parseLong.A flag with 100 splits of 2 shards did this up to 200 times per evaluation, although its shards use only 2 distinct salts.
Additional Notes
Changes
ShardHasher(new, package-private) belongs to a single evaluation:salt,-and the targeting key into a reused buffer and hashes the buffer with a reusedMessageDigest. No string or digest object is created for each shard.totalShards.FlagEvaluator.evaluatecreates the hasher before the first split that has shards, after theTARGETING_KEY_MISSINGcheck.matchesShardtakes the hasher.getShardandgetMD5Hashare removed.ShardHasherTest(new) checks the new code against a copy of the removed algorithm:totalShardstriples. The strings mix ASCII, 2-, 3- and 4-byte UTF-8, and unpaired surrogates.totalShardsgoes up to 2^32−1.hashlib.totalShards, and two interleaved evaluations stay independent.CanonicalFixtureTestand the other module tests pass unchanged.flowchart LR E[evaluate] --> H["ShardHasher (this evaluation)"] H --> C{salt cached?} C -- yes --> R[reuse hash] C -- no --> D["thread's MessageDigest + buffer<br/>first 4 bytes → unsigned int"] R --> M["% totalShards → ranges"] D --> MScale suite results
ScaleSuiteBenchmark.evaluateonmaster(5e0370dbbe) and on this PR (f59c5d7756,mastermerged in), built from the same fixtures (508a342). AWS workspace, Intel Xeon Platinum 8175M, 16 vCPUs, JDK 21.0.10, JMH AverageTime, 1 fork, 3 warm-up and 5 measurement iterations of 2 s,-prof gc. The runs alternated betweenmasterand this PR under a shared lock, so no other benchmark ran at the same time. The load stayed around 2, so times carry a few percent of error; allocation is exact.scale/splitscasemasterscale-rollout-allocations(subject-0), 50 allocations with distinct saltsscale-rollout-allocations(subject-38)scale-rollout-allocations(subject-21)scale-targeted-rollouts(subject-67), rollouts behind aplanrulescale-targeted-rollouts(subject-48)scale-targeted-rollouts(subject-0)Cases 0–2 are rollout-only, and cases 9–11 mix targeting rules with rollouts. The
scale-many-splitscases (3–5) gain the most, since 100 splits share 2 salts. Measured before the latestmasterwas merged in, those cases went from 1.4–112 µs to 0.8–8.7 µs.The other case files have no sharded splits on their hot path. Measured against the pre-merge base, which has the same evaluator code:
scale/variations,scale/flagsandscale/ruleskeep their allocation (28,067 B, 330 B, 1,904 B), and their times are within noise.Hashing now allocates one hasher of about 40 B per evaluation that reaches a sharded split. The rest of the 408 B that remain in every case comes from the rest of the evaluation. A flag with one salt keeps it in fields and allocates no table. A flag with more salts allocates a small table: 96 B for 2 to 7 salts, about 2.1 KB for 50.
These numbers come from one benchmark thread, whose digest and buffer are already created. A new thread creates both once (see Limits).
After review, each hash also resets the digest (see Decisions). The numbers above include the reset.
Decisions
The digest's first 4 bytes, not the hex string. Big-endian, they are the number that the first 8 hex characters encode, so the result is bit-identical. Other Datadog SDKs compute the shard from the same 4 bytes.
A hasher per evaluation, with JDK types in the thread-locals. A per-thread hasher would allocate nothing, but it has three problems:
EvaluationContextthat evaluates a flag) would overwrite the outer evaluation's targeting key.The thread-locals hold only the
MessageDigestand a byte buffer. After each hash the buffer is zeroed and the digest is reset, and buffers above 8 KiB are not kept. The reset matters: afterdigest(), the JDK's MD5 keeps the last 64-byte input block, which holds the targeting key, until the next input orreset()(checked on JDK 11, 17 and 21). The cost is the per-evaluation hasher and, for flags with more than one salt, the table above.Cache the hash, not the shard. The hash depends only on the salt and the key, so shards that share a salt but differ in
totalShardsreuse it.A hand-written UTF-8 encoder.
String.getBytesallocates, and aCharsetEncoderneeds wrapping buffers. The encoder replaces an unpaired surrogate with?likegetBytes, and the random test compares the two byte for byte.Limits. On virtual threads, or on any thread that evaluates only once, each new thread creates its own
MessageDigestand buffer. That is still less than before, when every shard created aMessageDigest.totalShards = 0still raises the same error as before.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