You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(rust): eliminate context cloning and merge duplicated evaluation paths (#112)
## Summary
- **Take owned `Value` instead of `&Value`** in all evaluate methods,
avoiding a deep clone of the context on every evaluation. This is the
biggest win for large contexts (1000+ attributes)
- **Merge duplicated evaluation methods**: `evaluate_flag_internal` +
`evaluate_flag_internal_pre_enriched` collapsed into single
`evaluate_flag_core` (-151 lines)
- **Add `merge_metadata_flag_set_only`** helper to avoid
`HashMap::new()` allocation on flag-not-found path
- **`enrich_context` now destructures owned `Value`** instead of cloning
the context map
Net: **-148 lines** (162 added, 310 removed)
## Motivation
The evaluation hot path cloned the context `Value` on every call:
- Regular path: `enrich_context` called `obj.clone()` to deep-copy the
entire context map
- Pre-enriched path: `context.clone()` passed to `evaluate_owned` even
though nothing needed modification
Since `evaluate_owned` → `Arc::new(data)` takes ownership anyway,
passing owned values from the start eliminates the clone entirely. The
WASM callers already own the parsed context, so this is free.
The two nearly-identical `evaluate_flag_internal` /
`evaluate_flag_internal_pre_enriched` methods (~130 lines each) were a
maintenance hazard — any bug fix had to be applied in both. Merged into
a single `evaluate_flag_core` with a `needs_enrichment: bool` parameter.
## Test plan
- [x] All 134 unit tests pass
- [x] All 36 integration tests pass
- [x] All 39 gherkin scenarios pass
- [x] All 6 metadata merging tests pass
- [x] `cargo clippy -- -D warnings` clean
- [x] WASM target builds successfully
- [ ] Run benchmarks to measure improvement on large contexts
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
0 commit comments