feat(evaluation): pre-evaluate static flags for host-side caching#68
Merged
Conversation
…e caching Static flags (no targeting rules) and disabled flags always return the same result regardless of context. Pre-evaluate them during update_state() and include results in the response so hosts can cache them and skip the WASM boundary entirely. Rust: UpdateStateResponse gains a preEvaluated map populated by a new pre_evaluate_static_flags() helper in FlagEvaluator::update_state(). Java: FlagEvaluator stores the map in a volatile cache that is replaced atomically on each updateState(). evaluateFlag() checks the cache first and returns immediately on hit, avoiding all WASM overhead for simple flags (~4.4µs → ~0.02µs). Closes #60 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
update_state()and return results in the responseFlagEvaluatorcaches these results and returns them directly fromevaluateFlag(), skipping the WASM boundary entirelyMotivation
JMH benchmarks showed a ~200x latency gap for simple flags: native JsonLogic at 0.022 µs/op vs WASM at 4.41 µs/op. The overhead comes from JSON serialization across the WASM boundary — but static flags don't need any of that, they always return the same result.
Changes
Rust
src/model/mod.rs: Addedpre_evaluated: Option<HashMap<String, EvaluationResult>>toUpdateStateResponsesrc/evaluator.rs: Addedpre_evaluate_static_flags()that evaluates all static/disabled flags with empty context duringupdate_state()Java
UpdateStateResult.java: AddedpreEvaluatedmap fieldFlagEvaluator.java: Addedvolatilecache populated onupdateState(), checked first inevaluateFlag()— cache hit skips WASM entirelyREADME.md: Updated Performance section with benchmark comparison tablesExpected performance impact
Test plan
cargo test— all Rust tests passcargo clippy -- -D warnings— cleancargo fmt -- --check— clean./mvnw test— all 30 Java tests pass (existing tests exercise static flags via cache)Closes #60
🤖 Generated with Claude Code