Skip to content

perf: Serialise evaluation context and resolve JSONPaths once per evaluation - #43

Merged
khvn26 merged 2 commits into
mainfrom
perf/cache-jsonpath-context
Oct 30, 2026
Merged

khvn26 merged 2 commits into
mainfrom
perf/cache-jsonpath-context

Conversation

@khvn26

@khvn26 khvn26 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

In this PR, we construct JSON paths at most once per evaluation.

Measured locally with the flagsmith-rust-client benchmarks, patched to this branch (median per call):

Benchmark Env Before After
get_identity_flags_no_traits large 574 ms 3.2 ms
medium 8.1 ms 0.51 ms
small 403 µs 92 µs
get_identity_flags_with_traits large 603 ms 4.4 ms
get_identity_segments_with_traits large 603 ms 4.2 ms
get_environment_flags large 531 µs 523 µs (unaffected)

The remaining per-call cost on large is mostly the single context serialisation.

…luation

Identity overrides are mapped to segments conditioned on
`$.identity.identifier`. Each such condition re-parsed the JSONPath and
serialised the whole evaluation context to JSON, so evaluating an identity
cost O(identity overrides × context size). With 1,000 identity overrides
and 1,000 features, a single evaluation took ~0.6–4.7s.

Evaluate all segments through a shared `SegmentEvaluator` that serialises
the context lazily, at most once, and caches the resolved value per
JSONPath. The public `is_context_in_segment` keeps its signature.
@khvn26
khvn26 requested a review from a team as a code owner October 30, 2026 10:10
@khvn26
khvn26 requested review from emyller and removed request for a team October 30, 2026 10:10
matthewelwell
matthewelwell previously approved these changes Oct 30, 2026
Comment thread src/engine_eval/segment_evaluator.rs Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants