Skip to content

Use the native ijson writer for compact whole-document JSON.GET - #1734

Open
fcostaoliveira wants to merge 4 commits into
RedisJSON:masterfrom
fcostaoliveira:perf/compact-root-native-writer
Open

fcostaoliveira wants to merge 4 commits into
RedisJSON:masterfrom
fcostaoliveira:perf/compact-root-native-writer

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Use the compact JSON writer from RedisJSON/ijson#34 for whole-document string replies. A legacy root GET (no path or .) writes the document into the Redis reply buffer. A single $ returns the same document inside a one-element JSON array. Both shapes can read the stored root directly. Formatted replies, other paths, JSON.PATH, JSON.MGET and expanded RESP3 replies continue through their existing handling.

The ijson update from 379dadf to 8489133 includes the benchmark suite (#29), one-probe removal of interned strings (#31), inline string handle construction (#33), and the native writer (#34). The two string changes also run on writes. ijson comparison

The default implementation for other JSON value backends delegates to serde_json.

Current revision

The branch includes RedisJSON master ba051ddf, which contains the newly merged static-path scanner. PR head 60811c00 adds regression coverage for a string escape past the first word, an unsigned integer above i64::MAX, a typed FP16 array, and the default RESP3 compact root reply. The two targeted live-server tests and all 458 Rust tests and doctests passed locally. The previous timing and review results below identify the pre-scanner revisions they compared. The Graviton4 results below use this new master. The new Fable review is in progress. Current CI

The current x86-64 Callgrind comparison measured 83 workloads. The largest instruction-count increase was 0.49% (eval/projection-keys). The five-fixture memory job found equal total key bytes in every case. The medium fixture used 64 B more process dataset RAM and the repeated-string replacement SET took 5.33% more server time. In six dedicated AMD pairs using the same Rust 1.100.0 compiler, the repeated-string SET cost was +1.05%. The medium fixture’s median process RAM difference was +64 B for master/PR and also +64 B for master against a copy of itself. An independent 20-pair rerun measured a master/PR median of 0 B. In all 80 processes across that rerun and its 20 A/A pairs, total key memory was 62,520 B, allocated dataset bytes grew by 66,000 B, and the remaining process variation matched the main Redis keyspace hash-table overhead byte-for-byte. Instruction counts · Memory and SET comparison

An independent Rust test also exercised the public default writer on serde_json::Value. For null, booleans, a maximum-width unsigned integer, escaped strings, Unicode and nested values, it kept a nonempty output prefix and appended exactly the bytes from serde_json::to_vec. The shipped RedisJSON backend exercises the ijson override. On arm64, the review measured a 144 B stack frame per nested object (96 B on master) and 208 B per nested array (224 B on master). At the enforced 128-level limit, an all-object chain uses about 6 KiB more stack.

Current command benchmark checks

All 51 hosted command workloads completed on master ba051ddf and PR 60811c00. Four lost more than 3% throughput in CI (GeoJSON ARRAPPEND, deep-path SET, integer-array SET and scalar SET). The table shows completed rechecks on dedicated AMD hardware. Each used the hosted run’s unmodified server, client, modules and workload files, with four alternating master/PR pairs. The module and tool hashes matched before and after each series. Percentages use median paired throughput change. The two SET guards from the previous review are still running on a separate dedicated host. Hosted command comparison

Command benchmark Hosted paired change Dedicated master req/s Dedicated PR req/s Four paired changes Median paired change
json_arrappend_geojson -4.17% 210,482 210,526 +0.02%, -0.02%, +0.02%, +0.00% +0.01%
json_set_auto_create_deep_paths -3.03% 294,152 298,543 +1.49%, -0.01%, +1.49%, +0.04% +0.77%
json_set_homogeneous_integer_arrays -3.36% 35,700 36,342 +0.90%, +1.82%, +1.83%, +1.81% +1.81%
json_set_sclr_pass_100_json -4.76% 370,398 363,676 -1.85%, -1.78%, +1.85%, -1.85% -1.81%
Paired master and PR rates on the dedicated host (requests/s)
Command benchmark Pair 1, master → PR Pair 2 Pair 3 Pair 4
json_arrappend_geojson 210,482.00 → 210,526.31 210,570.64 → 210,526.31 210,482.00 → 210,526.31 210,437.72 → 210,437.72
json_set_auto_create_deep_paths 294,100.34 → 298,489.66 294,100.34 → 294,083.03 294,204.16 → 298,596.59 298,471.81 → 298,596.59
json_set_homogeneous_integer_arrays 36,016.57 → 36,342.49 35,693.89 → 36,342.49 35,705.36 → 36,357.03 35,693.89 → 36,338.53
json_set_sclr_pass_100_json 370,480.12 → 363,609.91 370,315.50 → 363,742.16 363,742.16 → 370,480.12 370,480.12 → 363,609.91

A separate dedicated AMD comparison repeated the six balanced blocks that had identified the places SET regression on the previous revision. Each block used master, master with only the ijson dependency update, and the complete PR. Their median rates were 3,566, 3,630 and 3,767 requests/s. The PR gained 5.64% against master within blocks (+7.53%, +3.73%, +5.67%, +5.62%, −0.04%, +7.53%) and 3.78% against the dependency-only build. The dependency update alone gained 1.78% against master. This used release builds with rustc 1.92.0, 10,000 preloaded keys and 50,000 overwrites in each of 18 cells. All 900,000 overwrites succeeded, every sampled readback matched and each sampled key used 89,556 B. The median paired PR change was 0 B for dataset RAM, −440 B retained and −376 B peak for the overall process.

Current Graviton4 end-to-end throughput

Direct client rates on master ba051ddf (includes the static-path scanner) and PR 60811c00. Redis 8.12.0, rustc 1.92.0 release with default flags, one pinned Neoverse-V2 server core, two separate client cores, 16 connections, pipeline 1. Each rate is the median of three interleaved rounds. Percentages use the median change within pairs.

Redis command Dataset Master req/s PR req/s Paired change
JSON.GET key $ Yelp 26,299 37,722 +43.43%
JSON.GET key Yelp 26,299 37,722 +43.43%
JSON.GET key $ Yahoo2 47,605 66,653 +40.01%
JSON.GET key Yahoo2 48,181 66,653 +38.34%
JSON.GET key $.n small object control 228,571 228,571 −0.01%

Each sample completed 500,000, 1,000,000 or 4,000,000 requests for Yelp, Yahoo2 or the control respectively, after 5,000 warm-up requests. The client timer has 250 ms resolution. Median server CPU per JSON.GET key $ was 37.84 → 26.32 µs on Yelp and 20.76 → 14.91 µs on Yahoo2. The host exposed 96 physical cores with no SMT or readable CPU-frequency controls. A separate parity run returned 935 byte-identical replies and 17 equivalent expanded replies across RESP2 and RESP3.

Document bytes were identical on every trial (42,400 B Yelp, 19,544 B Yahoo2, 32 B control). Median end-of-run used memory was 1,175,544 → 1,175,504 B. The median Redis process high-water mark was 1,816,056 → 1,840,400 B (+24,344 B), with a higher PR peak in two of the three rounds.

A second Graviton4 ran the identical modules with a fresh build of the same Redis 8.12.0 tag and allocator. Two identical master binaries reproduced the roughly 24 KB step in either direction. Repeating the original full 500,000-request Yelp row across four PR/master pairs gave a median process peak change of −32 B and median retained change of −8 B. Four master/master control pairs on that same row included a +24,400 B peak difference. Six master/PR pairs with the same queued replies had a median peak change of −32 B (range −40 to −24 B), versus 0 B for six master/master pairs. In a separate instrumented server, the candidate’s peak for each GET was equal to master’s or 16 B lower across 76 matched states and 3,840 GETs. In that reproduction, the process peak depended on queued reply buffers and when Redis sampled its allocator. The first throughput run did not record which allocation produced its high-water mark.

A separate process-scoped topdown-profiler capture of Yelp compact root GET on the same binaries recorded five 1-second intervals per side. Mean L1 slot shares, master → PR, were Frontend Bound 22.2% → 19.7%, Bad Speculation 2.7% → 2.5%, Backend Bound 26.3% → 25.9%, and Retiring 48.8% → 52.0% (rounding to 0.1%). Matched symbolized CPU profiles were saved locally. The latest revision has the following platform coverage.

x86-64 Intel x86-64 AMD Zen 5 arm64 Neoverse-V2 (Graviton4) arm64 Apple M-series
Not measured on this revision. The dedicated throughput run targeted Graviton4. Dedicated SET and ARRAPPEND rechecks, memory attribution and dependency-only SET comparison above. Compact-root GET throughput, reply parity, memory and pipeline counters above. Not measured on this revision. The dedicated throughput run targeted Graviton4.
Earlier revision, before the static-path scanner merged

Correctness on ae5c7cdd

  • 451 Rust tests passed locally in the default configuration, single-threaded, and the release module built.

  • The new command-level test passed against a live server. A separate comparison with RedisJSON master 693e4c35 on the same server binary returned 935 byte-identical RESP2/RESP3 replies over 17 documents, plus 17 equal RESP3 expanded replies with map order ignored. Cases included escaped text, typed arrays, missing keys, errors, formatting and projection-independent commands.

  • The optional all-features run on macOS reproduced two failures on both master and this branch. test_get_memory saw 864 versus the expected 480 bytes on both. The following shared-string test failed on the poisoned lock.

  • On ae5c7cdd, the unchanged Gungraun/Callgrind check reports zero regressions across all 83 workloads. $.numbers.append(64) now takes exactly 22,478 instructions on both master and the PR, after making the JSON null fallback lazy during array element conversion. CI benchmark

The remote Fable 5.2 xhigh review found no correctness blocker on ae5c7cdd but required both SET reruns to clear 3% before merge. The places SET missed that condition. On arm64, the review passed 453 Rust tests and 322 shipped pytest cases. It compared 694,363 replies against master over 6,184 documents. Every reply matched byte-for-byte or differed only in unordered map key order.

Command and memory checks on ae5c7cdd

On the same master and PR revisions, all 51 x86-64 command benchmarks completed. Full-document Yelp GET measured 11,350 → 16,117 req/s (+41.45%), and Yahoo2 GET measured 38,271 → 56,732 req/s (+48.28%). Percentages use the CI driver’s paired changes where it collected multiple attempts. Two SET workloads crossed 3% slower in the hosted run. The full-document places fixture fell 3.36%, and Yelp’s nested message.code SET fell 3.34%. Four dedicated AMD pairs using the same CI modules, client, server and workload files measured +0.84% on Yelp’s nested SET and −3.65% on the full-document places SET (individual changes −4.96%, −2.95%, −3.08%, −4.22%). That result blocked the pre-scanner revision. The same workloads are running on the refreshed branch. Command benchmark report

A separate AMD comparison on the pre-scanner base used six balanced blocks of 50,000 full-document SETs apiece after loading 10,000 keys. Median throughput was 3,629 req/s on master, 3,696 req/s on master with only the ijson dependency update, and 3,442 req/s on ae5c7cdd. The PR was 5.16% slower than master and 6.88% slower than the dependency-only build using the median within-block change. Every cell had the same key count and readback hash. This confirms a slowdown on that revision and fixture. Its cause is still open, and the refreshed PR needs the same check against master ba051ddf.

The memory comparison reported equal total key bytes for all five fixtures. Dataset RAM (used memory after load minus the empty-process baseline) was equal or lower on the PR for every fixture. Memory comparison

Graviton4 throughput before the scanner merged

Direct client measurements against RedisJSON master 693e4c35 and PR head ae5c7cdd. Rates are median completed requests per second over three paired rounds. The percentage is the median of the three within-round changes.

Workload Master req/s PR req/s Change Paired range
Yelp, JSON.GET key $ 25,627 37,719 +47.2% +47.2% to +47.2%
Yahoo2, JSON.GET key $ 45,964 66,653 +45.0% +45.0% to +47.5%
Yelp, JSON.GET key 25,628 37,722 +47.2% +47.2% to +47.2%
Yahoo2, JSON.GET key 45,962 66,658 +45.0% +43.4% to +47.5%
Small object, JSON.GET key $.n 183,883 183,900 +0.0% -0.0% to +0.0%

One dedicated arm64 Neoverse-V2 host, Redis server and redis-benchmark 8.12.0, Rust 1.92.0 release builds. The server used one pinned core and the two client threads used two other pinned cores on loopback. Each workload used 16 clients, pipeline depth 1, and 5,000 warm-up requests per sample. Each measured sample sent 500,000 requests per Yelp command, 1,000,000 per Yahoo2 command and 4,000,000 for the control. Master and PR alternated first across rounds. All read commands completed without errors. The host exposed no CPU-frequency governor reading. Intel, AMD and Apple throughput were outside this Graviton4 run.

The machine exposed 96 Neoverse-V2 cores with one thread per core. Both modules used rustc 1.92.0 in release mode with no additional Rust compiler flags. The client's 250 ms completion check corresponds to about 1.3–1.9% of a target-row sample, which explains several equal rounded rates. The median server CPU time per completed JSON.GET key $ was 38.74 → 26.24 µs on Yelp and 21.73 → 14.87 µs on Yahoo2. The control was 5.40 → 5.39 µs.

RedisJSON reported identical document sizes in every round (42,400 B for Yelp, 19,544 B for Yahoo2 and 32 B for the control). Median end-of-run Redis used_memory was 1,175,520 B on master and 1,175,512 B on the PR. Median used_memory_peak was 1,816,112 B and 1,816,008 B respectively.

The same-host RESP2/RESP3 comparison against master also passed on both the pin-only build and the PR, with 935 byte-identical replies and 17 equivalent expanded replies per comparison.

Individual rounds and dependency-only comparison
Workload Master rounds 1 / 2 / 3, req/s PR rounds 1 / 2 / 3, req/s
Yelp, JSON.GET key $ 25,625 / 25,627 / 25,627 37,719 / 37,719 / 37,722
Yahoo2, JSON.GET key $ 45,958 / 45,964 / 45,964 66,653 / 66,653 / 67,783
Yelp, JSON.GET key 25,628 / 25,628 / 25,625 37,722 / 37,722 / 37,722
Yahoo2, JSON.GET key 45,962 / 46,496 / 45,962 66,649 / 66,658 / 67,783
Small object, JSON.GET key $.n 183,866 / 183,883 / 183,891 183,908 / 183,874 / 183,900

A separate six-round comparison exercised every ordering of master, master with only the ijson dependency update, and the earlier writer commit 38e454a7, with 100,000 requests per workload. The shorter runs give coarser estimates because redis-benchmark checks completion on a 250 ms timer. Redis benchmark client

Workload Master req/s Pin only req/s Earlier writer req/s
Yelp, JSON.GET key $ 24,981 24,981 36,337
Yahoo2, JSON.GET key $ 44,405 44,415 66,622
Yelp, JSON.GET key 24,981 24,981 36,337
Yahoo2, JSON.GET key 44,425 44,405 66,622
Small object, JSON.GET key $.n 133,156 133,156 133,156

[!NOTE]
Low Risk
Read-path optimization with a narrow fast path ($, no formatting); behavior is covered by new tests and byte-identical reply comparisons, with modest risk only if compact JSON output diverges from serde on edge cases.

Overview
Bumps the ijson dependency and adds a write_compact_json hook on SelectValue, with IValue using ijson::to_writer instead of serde for serialization.

JSON.GET now has a fast path for unformatted $ reads: the stored root document is written straight into a StringBuffer reply (JSONPath shape wraps it in […]; legacy mode omits the wrapper), skipping JSONPath evaluation and serde round-trips for that case. Formatted GET, other paths, and RESP3 expanded replies keep the existing code paths.

A small append() fix uses unwrap_or_default() when converting array elements. New pytest coverage checks byte-stable compact replies for varied root documents.

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

@fcostaoliveira
fcostaoliveira marked this pull request as ready for review December 3, 2026 16:24
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.53%. Comparing base (ba051dd) to head (60811c0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1734      +/-   ##
==========================================
+ Coverage   88.48%   88.53%   +0.05%     
==========================================
  Files          18       18              
  Lines        7026     7040      +14     
==========================================
+ Hits         6217     6233      +16     
+ Misses        809      807       -2     

☔ 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.

@gabsow

gabsow commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

@AvivDavid23 please check 🙏

This branch has not been deployed

No deployments
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