Repository navigation
Scan static JSONPaths without pest - #1729
Open
fcostaoliveira wants to merge 2 commits into
Open
fcostaoliveira wants to merge 2 commits into
fcostaoliveira wants to merge 2 commits into
Conversation
`$` and chains of `.key`, `[n]`, `.[n]`, `['key']` and `["key"]` are the most common paths (JSON.GET/JSON.SET on the root or one element), but every command compiled them through the full pest grammar, costing a dozen allocations for a path like `$.[7]`. `compile` now tries `scan_static_path` first. On success the query root is `QueryRoot::Static(Vec<StaticStep>)`, evaluated by `PathCalculator::calc_static` with direct lookups (the user path tracker is filled in the same order). The `lib.rs` entry points, including `exists`, dispatch on `QueryRoot`, and `pop_last*`, `is_static` and `size` have static arms. A rejected path allocates nothing and goes through pest unchanged, so error messages stay the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1729 +/- ##
==========================================
+ Coverage 88.24% 88.47% +0.23%
==========================================
Files 18 18
Lines 6871 7022 +151
==========================================
+ Hits 6063 6213 +150
- Misses 808 809 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Cover the saturating index parse and the leading-space quoted key that the scanner leaves to pest, both as unit tests and through the module. 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
json_path::compilenow tries a small hand-written scanner before pest. It accepts$followed by any chain of.key,[n],.[n],['key']and["key"]. On success the query root isQueryRoot::Static(Vec<StaticStep>), andPathCalculator::calc_staticevaluates it with directget_key/get_indexlookups.lib.rsentry point dispatches onQueryRoot. That includescalc_once,calc_once_with_paths,visit_once_with_paths,calc_once_pathsand the newexists.pop_last,pop_last_object_key,is_staticandsizehave static arms.Query::rootchanges type. Nothing in the repository reads it outsidejson_path.E2E results: RedisJSON command throughput
Throughput of each benchmarked command,
mastervs this PR.Graviton4 (arm64 Neoverse-V2, AWS m8g.4xlarge). The official
redis:8.12.0server is pinned to one core and loads the RedisJSON module built frommaster7ecc513 (ijson379dadf) or from the PR head. memtier_benchmark runs on 14 other cores with pipeline 1: 8 connections × 2 threads for jsonsl-1 and yelp, 25 × 4 for 10-item, 25 × 8 for session. Each run lasts 30 s; every build gets 6 interleaved runs, and the table shows the median ops/s. p is an exact permutation test (6 vs 6). The server core was saturated (0.99 cores) in every cell except some multipath-5 cells (0.96). A byte-identical copy ofmasterran as an A/A control. Δ = patched / base − 1; bold means p < 0.05.kis the key.Datasets:
itemsarray of 10 objects).JSON.GET k $.[7]JSON.SET k $.[0] '"foo"'JSON.GET k $.businesses[?(@.avg_rating>=4.5)].nameJSON.GET k $JSON.GET k $..nameJSON.GET k/ 10 %JSON.SET k $ '{"userId":"user-k","organizationId":"org-id","role":"admin",…}'(≈405 B document)JSON.GET k $.items[?(@.qty>5)].nameJSON.GET k $.items[*].name $.items[*].qty $.items[*].price $.items[*].attrs.color $.items[*].attrs.size¹JSON.TYPE k $.items[*].attrsJSON.OBJLEN k $.items[*].attrsJSON.STRAPPEND k $.items[*].name '"-x"'/ 10 %JSON.SET k $.items[*].name '"Item"'JSON.SET k $.items[*].extra [1,2,3,4,5,6,7,8]/ 50 %JSON.ARRAPPEND k $.items[*].extra '"tag"'¹ multipath-5: 8 of 36 cells ran at 0.96 server cores (3
master, 3 P2, 2 P1+P2), so the base side of this row may be slightly client-limited (up to about 4 %).² Not usable against
master: on this suite the A/A control (mastervs its byte-identical copy) moved +12.1 % (p 0.019).master's six runs split into two groups (57–62k and 70–74k ops/s) from per-run server system time, while user CPU per request was flat.The
JSON.TYPErow (p 0.048) falls inside that suite's A/A band (−2.8 %), and its user CPU per request went down (5.15 → 4.38 µs), so it is not counted as a regression.A/A control (
mastervs its copy): every suite moved by at most ±6.5 % with p ≥ 0.076, except the STRAPPEND/SET suite (+12.1 %, p 0.019).used_memorystayed within 0.1 % ofmasteron every suite.Why
$and single-element paths are the most common paths in practice, for exampleJSON.GET key $andJSON.SET key $.[0] .... Each command compiled them through the full grammar:$.[7]cost 12 allocations (3.5 KB) before the lookup;$alone cost 12 allocations, and is 0 now.Results
The benchmarks ran on RedisJSON v8.12.0 with and without this patch on one arm64 Neoverse-V2 host (Graviton4). The rebase onto
masterwas checked for correctness (below); the timings were not re-run on master.json_pathmicro (ns per call, median of 6):$$.[7]$.[7](compile + calc + serialize), 1-level doc$small doc$10-item doc$large doc (~30 KB)Allocations per call:
$$.[7]Server, µs of server CPU per request. Redis 8.12.0, server pinned to one core, memtier on other cores, 6 interleaved runs, plus an A/A control. p-values are from a permutation test.
JSON.GET k $.[7](200K keys)JSON.SET k $.[0] "..."(200K keys)JSON.GET k $, 10 %JSON.SET k $)JSON.GET k(~30 KB doc)JSON.TYPECorrectness (on this branch, rebased on
master7ecc513)cargo test --workspacegives 453 passed and 0 failed, the same asmaster.tests/pytest/tests.shagainstredis-server8.12.0 passes 377 of 377 in each of general,--use-aof,--use-slavesand--env oss-cluster, the same asmaster.master:compileerrors,calc_once,calc_once_with_paths,calc_once_paths,visit_once_with_paths(first and all),exists,create/calc,create_with_generator/calc_paths,is_static,size, and thepop_last*sequences;cargo fmt --checkandcargo clippy -p json_pathare clean.🤖 Generated with Claude Code
Note
Medium Risk
Touches core compile/eval for the most common JSON paths; behavior is intended to match pest, but parity depends on careful scanner edge-case handling (indexes, quoted keys).
Overview
json_path compilation now fast-paths simple root-relative paths via a hand-written
scan_static_pathscanner before invoking pest. Accepted paths are stored asQueryRoot::Static(Vec<StaticStep>)and evaluated withPathCalculator::calc_static(direct key/index walks) instead of walking a pest parse tree.Query.rootis now aQueryRootenum (StaticvsPest). Public APIs inlib.rs(calc_once,exists,calc_once_with_paths,visit_once_with_paths,calc_once_paths) and query helpers (pop_last,pop_last_object_key,is_static,size) branch on that representation. Non-matching inputs still use pest unchanged—no allocations on reject.Unit and pytest tests cover overflowing indexes and quoted keys that must stay on the pest path (e.g. leading space after
").Reviewed by Cursor Bugbot for commit 80edb6e. Bugbot is set up for automated code reviews on this repo. Configure here.