Skip to content

MOD-19160 Json Path perf improvements - #1661

Merged
AvivDavid23 merged 9 commits into
masterfrom
MOD-19160-json-path-perf
Oct 4, 2026
Merged

AvivDavid23 merged 9 commits into
masterfrom
MOD-19160-json-path-perf

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Optimize JSONPath parsing and evaluation by reducing repeated work and allocations.

  • Grammar: Parse shared operands once instead of retrying alternatives, especially in nested filters such as $.a[[email protected][[email protected]]].
  • Object iteration: Iterate borrowed entries directly, avoiding temporary vectors during recursive searches such as $..uid.
  • Regex cache: Separate search/full-match entries so cache hits avoid allocating pattern strings or formatting anchors.
  • Root operands: Cache root-path results across filter candidates. For $.rows[[email protected] > $.threshold], resolve $.threshold once. Enable caching only for multi-candidate filters.
  • Existence filters: Stop at the first selected node. For $.rows[[email protected]], finding one flag avoids searching the remaining descendants.
  • Result collection: Return the existing result vector directly, avoiding another allocation and transfer.
  • String equality: Compare borrowed strings, avoiding allocations during membership checks and deep equality.
  • Coverage: Add grammar and cache-scope tests; expand CI benchmarks from 72 to 81 cases, including grouped filters, root-existence checks, and single-candidate filters.
  • CI reporting: Add a visual job summary showing baseline/current timings, percentage changes, and confirmation results.

Observed locally against master, across three paired runs on 13 workloads:

  • Compilation: ~35% less time for $.rows[0].score; ~56% for the root-comparison filter.
  • Evaluation: ~15% less time for recursive searches; ~23% for simple lookups.
  • Root reuse: ~18% less time for scalar comparisons; ~82–92% for repeated recursive root operands.
  • Existence early exit: ~99.7% less time when a match appears before a large subtree.
  • Arithmetic projection was ~0.9% slower; no measured case exceeded 5% slowdown.

Measured before/after path evaluation time, using medians across three local Criterion runs. Compilation, Redis command handling, and response serialization are excluded.

First two commands use this document: 256 rows and 128 limits. Comments mark omitted entries.

{
  "rows": [
    {"uid": 0, "score": 0},
    {"uid": 1, "score": 1},
    // ... rows 2–254
    {"uid": 255, "score": 255}
  ],
  "threshold": 128,
  "thresholds": [
    {"limit": 1000},
    {"limit": 1000}
    // ... 126 more identical entries
  ]
}

Existence query ($.rows[[email protected]].uid) uses 128 rows, each containing a 341-object subtree:

{
  "rows": [
    {
      "uid": 0,
      "flag": false,
      "children": {
        "uid": 1,
        "name": "branch",
        "children": [
          // ... four children per branch, four levels deep
          // Leaves: {"uid": 1, "name": "leaf"}
        ]
      }
    }
    // ... 127 more rows, each with the same subtree
  ]
}
Equivalent command Fixture Before After
JSON.GET doc '$.rows[[email protected] > $.threshold].uid' 256 rows, one root threshold 0.071 ms 0.057 ms
JSON.GET doc '$.rows[[email protected] > $.thresholds..limit.sum()].uid' 256 rows, 128 root limits 3.634 ms 0.297 ms
JSON.GET doc '$.rows[[email protected]].uid' 128 rows, each with an immediate flag and a large subtree 6.089 ms 0.020 ms

Root caching avoids repeated traversal across candidates. Existence filters stop at the first match, making the largest gain dependent on match position


Note

Medium Risk
Changes core JSONPath parsing and filter evaluation semantics with broad benchmark coverage, but behavior is heavily regression-tested; CI workflow changes affect gating timing, not runtime query results.

Overview
This PR speeds up JSONPath compilation and evaluation and reworks how CI compares performance against master.

Evaluator and grammar: Nested filters compile with less parser backtracking via a factored method_chain and explicit parenthesized filter parsing ([?(@.x > 1)]). Evaluation avoids extra allocations when walking borrowed objects, returns the internal result buffer directly, compares strings via borrowed as_str, and splits regex caching into lazy search vs full-match maps. Multi-candidate filters cache repeated $… operands and existence checks stop at the first match; caches stay off for single-row filters and cap large root lists.

Benchmarks and CI: The Criterion suite grows to 81 workloads (grouped filters, root/existence cases, etc.) and writes each workload’s JSONPath to paths.jsonl for reports. The JSONPath job drops cached cross-run baselines, checks out master and the PR on the same runner, intersects benchmark names, remeasures flagged ≥5% slowdowns on both revisions, and emits a markdown job summary (tables, status, optional JSONPath column) via jsonpath_benchmark_gate.py --summary. Partial workload overlap is allowed; new names show “No master baseline” instead of failing the compare step.

Reviewed by Cursor Bugbot for commit 1088990. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.29851% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.13%. Comparing base (d678955) to head (1088990).

Files with missing lines Patch % Lines
json_path/src/json_path.rs 90.22% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1661      +/-   ##
==========================================
+ Coverage   88.06%   88.13%   +0.06%     
==========================================
  Files          17       17              
  Lines        5957     6049      +92     
==========================================
+ Hits         5246     5331      +85     
- Misses        711      718       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread json_path/src/json_path.rs Outdated
);
let result = Self::results_to_term(new_calc_data.results);
if let Some(cache) = &mut calc_data.root_cache {
cache.insert(key, result.clone());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we limit the cache size or skip large results? Repeated $ paths keep separate result lists in memory, which can add up quickly.

@AvivDavid23
AvivDavid23 merged commit 40588df into master Oct 4, 2026
61 checks passed
@AvivDavid23
AvivDavid23 deleted the MOD-19160-json-path-perf branch October 4, 2026 11:09
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