Skip to content

Add criterion microbenchmarks for the RedisJSON call paths, a memory referee, and benchmark docs - #29

Merged
fcostaoliveira merged 29 commits into
RedisJSON:masterfrom
fcostaoliveira:pr/benches-callpaths
Nov 26, 2026
Merged

fcostaoliveira merged 29 commits into
RedisJSON:masterfrom
fcostaoliveira:pr/benches-callpaths

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Benchmarks only, no library code changes. Adds under benches/:

  • callpaths.rs: eight criterion groups, one per kind of operation RedisJSON performs on ijson, with argument shapes taken from RedisJSON's ivalue_manager.rs, formatter.rs, key_value.rs, rdb_persistence.rs, defrag.rs and json_path: parse (JSON.SET, compact objects and FPHA float arrays, one key per line for NDJSON), serialise (JSON.GET, compact and indented), lookup (JSONPath steps and get/get_mut by key on the 28-key yelp business, an 8-key small object and a 128-key wide object, with a typed-array control), mutation (member set/delete, MERGE into occupied entries, array insert/pop/trim, NUMINCRBY, STRAPPEND), typed (homogeneous arrays: build, retag, slice reads), clone-drop (clone, drop, and drop of the last reference), cbor (RDB save/load incl. the streaming codec and compressed variants), mem-defrag (mem_allocated, and defrag after defrag_start's cache reinit). The string cache is initialised as RedisJSON does at module load, init_shared_string_cache(true) (the locked cache); mutation benchmarks restore their own state so no setup clone confounds the measured routine, and outputs are dropped outside the timed section unless the drop is what is measured.
  • memory.rs: deterministic retained/peak bytes and allocation counts per fixture and call path through mockalloc, IValue::mem_allocated() beside the allocator's truth, CBOR payload sizes, size_of for the core types. Markdown or --json output.
  • corpus.rs: the parse, drop, serialise and clone call paths over real JSON files fetched by fetch-datasets.sh (one key per document, one per line for NDJSON), after a memory table per file. Without datasets it prints the fetch command and exits 0.
  • fetch-datasets.sh and datasets.sha256: download the benchmark corpus from a public S3 mirror, check every asset against its pinned sha256 before unpacking, in presets (quick 165 MB download, standard, all) or by family.
  • examples/mem_attribution.rs: attributes a parsed document's retained bytes to objects, arrays, numbers and unique heap strings and shows the gap to mem_allocated().
  • benches/README.md: a quick start, what each group measures and which RedisJSON command it stands for, the datasets and their licences, how to run, the A/B protocol that has held up against code-placement noise on the 15–60 ns routines (same commit/toolchain/machine, interleaved pairs, median delta with the base's spread, 3% noise level and re-run rule, optional 64-byte alignment flags to take placement out, time-and-memory decision, four platform classes), and a "For AI agents" section stating the contract an automated agent must follow when it proposes a change (name the RedisJSON call path, measure on one machine, report time and memory with spread, keep harness and candidate commits apart, confirm end to end in RedisJSON). A short pointer is added to the top-level README.

Fixtures are minified copies of RedisJSON's tests/files and tests/benchmarks/datasets documents (yelp, yahoo2, a Google Maps place reply, homogeneous integer arrays, parser-0000, pass-100), two arrays generated with a fixed seed, and refsnp-unsupported-400.ndjson: 400 NCBI dbSNP RefSNP records (build 157, public domain), benchmarked one key per line.

Cargo.toml gains criterion as a dev-dependency (no default features, cargo_bench_support only) and three [[bench]] entries with harness = false. CI builds the benches in both configurations (cargo bench --no-run, --no-default-features and --features thread_safe), since cargo build and cargo test skip bench targets.

New in this revision

  • r6–r8 benchmarks: clone-drop/drop-last-ref/* (the drop of the only reference, so every string leaves the cache), mem-defrag/defrag-reinit-yelp (defrag of the only copy after defrag_start's cache reinit) and mem-defrag/defrag-cycle-yelp (the same with the reinit timed).
  • Datasets fetch script: benches/fetch-datasets.sh reads a public S3 mirror, sha256-pinned per asset, with quick / standard / all presets.
  • Bundled NCBI RefSNP fixture: refsnp-400, one key per line, in parse, serialise, clone-drop and the memory referee.
  • Corpus bench: --bench corpus, RedisJSON's call paths over the fetched files.
  • README quick start.
  • Memory gate in CI: a Memory gate job fetches the base branch's tip when it runs and measures it, and the same tip with the PR merged in, with this suite's memory referee (so commits that reached the base after the PR branched off are on both sides). It compares every retained and peak byte count, mem_allocated and size_of: the default build, whose counts repeat exactly, fails on any growth; thread_safe, whose sharded cache's random hash seed moves small fixtures by up to ~13 % between runs, uses the median of 5 runs per side and fails above +5 %. Script: .github/scripts/memory-gate.sh; table in the job summary.
  • Review fixes:
    • clone-drop/clone/* times the clone only; clones are dropped outside the timer (LargeInput batches, so 8 KB typed-array clones no longer reach gigabytes of resident memory).
    • Every bench, the memory referee and mem_attribution initialise the locked string cache, init_shared_string_cache(true), as RedisJSON does.
    • defrag-copy-yelp reinitialises the string cache in setup (BatchSize::PerIteration), as defrag_start does, so every string moves.
    • str-append alternates two suffixes, so each iteration interns a new string and drops the old one, as str_append does.
    • The memory referee's parse retained and mem_attribution no longer depend on fixture order (a dropped parse of the fixture first); CBOR decode retained is measured with the parsed document dropped; mem_attribution counts short strings as heap strings in the thread_safe build.
    • array-trim-typed-1024-to-512 and retag-on-string-push-1024 use LargeInput.
    • business-28-{hit,miss} and object-insert-remove-28 (were -22): the yelp business has 28 keys.
    • CI builds the benches in both configurations.
    • Comments state their reasons instead of pointing to documents outside this repository.
    • typed/build-f64-push-1024 and typed/build-i64-try-extend-16k drop the built array after the batch, outside the timer.
    • The corpus bench counts a realloc as an allocation, as mockalloc does, so its allocation column agrees with --bench memory.
    • fetch-datasets.sh re-downloads an asset when any file it unpacked has been deleted.
    • cbor/stream-encode-yelp-fresh-encoder and cbor/stream-decode-yelp drop the encoder and decoder after the batch, outside the timer.
    • parse/compact-objects-cold/* beside the warm compact-objects/*: no other copy alive, so every string is inserted into the cache.
    • mutation/array-trim-typed-1024-middle-512: ARRTRIM keeping the middle half, through arr_trim's rotate then truncate.
    • clone-drop/drop-last-ref covers documents with strings only (a typed array's last-reference drop is drop's work, and the timer dominated it).
    • The corpus memory table's column is parse retained incl. string table, distinct from --bench memory's parse retained.

Why

Having the suite in-tree lets any future ijson change, human or agent-authored, be judged on the paths RedisJSON exercises with time and memory together. Earlier versions of it were used to measure #27 and #28, and caught confounds in its own harness (an iter_batched setup clone, a benchmark that timed a None); this revision fixes the ones found in review.

Checks

  • On arm64 Apple M-series (macOS) and x86-64 Sapphire Rapids (Linux): cargo test --lib -- --test-threads=1 passes with --no-default-features (134 tests) and --features thread_safe (129); cargo bench --no-run builds in both configurations; cargo bench --bench callpaths -- --test runs all 79 benchmarks once in both; --bench memory and the mem_attribution example run in both; on Linux, --bench corpus -- --test runs its 32 benchmarks over the eight default files.
  • cargo fmt --check passes; clippy reports nothing in benches/ or examples/, and the library's own clippy output is unchanged.
  • No change under src/; the unit tests and fuzz targets are unaffected.
  • The fixes change what several benchmarks time (string cache, clone, defrag, str-append), so baselines taken before this revision are not comparable with it.

🤖 Generated with Claude Code


Note

Low Risk
Benchmark-only and CI automation with no library code changes; the memory gate may fail PRs that increase retained memory even when behavior is correct.

Overview
Adds a full benchmark harness around RedisJSON’s real ijson usage: Criterion callpaths (parse, serialise, lookup, mutation, typed arrays, clone/drop, CBOR, defrag), deterministic memory referee via mockalloc, and optional corpus runs over downloaded datasets. Cargo.toml picks up criterion and three [[bench]] targets; bundled fixtures plus fetch-datasets.sh / pinned datasets.sha256 support larger corpus runs.

CI now cargo bench --no-run in default and thread_safe builds, and a new memory gate job runs .github/scripts/memory-gate.sh: base-branch tip vs that tip with the PR merged, same memory harness—zero tolerance on retained/peak growth in the default build, +5% median threshold for thread_safe. memory_gate.py diffs JSON bench output into the job summary.

Docs: benches/README.md (A/B protocol, agent contract), README pointer, examples/mem_attribution.rs. .gitignore ignores benches/datasets and __pycache__. No changes under src/.

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

fcostaoliveira and others added 2 commits November 24, 2026 17:03
…ry referee

benches/callpaths.rs: eight criterion groups, one per RedisJSON call path (parse, serialise, lookup, mutation,
typed arrays, clone/drop, CBOR, memory accounting/defrag), argument shapes taken from RedisJSON's
ivalue_manager.rs, formatter.rs, key_value.rs, rdb_persistence.rs and json_path. The string cache is initialised
as OSS RedisJSON does (init_shared_string_cache(false)); mutation benchmarks restore their own state so no
iter_batched setup clone confounds the measured routine.

benches/memory.rs: deterministic retained/peak bytes per fixture and call path through mockalloc, beside
IValue::mem_allocated(), plus size_of the core types.

examples/mem_attribution.rs: attributes a parsed document's retained bytes to objects, arrays, numbers and
unique heap strings and shows the gap to mem_allocated() (the intern table).

Fixtures are minified copies of RedisJSON's tests/files and tests/benchmarks/datasets JSON documents.
No library code changes.
…act for AI agents

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread benches/callpaths.rs Resolved
Comment thread benches/callpaths.rs Resolved
…section

CI runs cargo fmt --check, which the bench files failed. The clone benchmarks now use iter_with_large_drop so the
destructor of the cloned tree is not timed (RedisJSON stores the clone on its target; the drop group measures
destruction). The ARRTRIM benchmark already returned the array to iter_batched, which drops outputs after the
measurement; a comment says so.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread benches/callpaths.rs Resolved
Comment thread benches/callpaths.rs Resolved
…r, occupied-entry merge benchmark

- parse/compact-objects, parse/fpha-f32, cbor/decode-yelp and cbor/decode-compressed-yelp hand their value back
  to criterion (iter_with_large_drop) so destruction is not timed; JSON.SET and RDB load keep the value.
- lookup/business-22-* is a table-backed object (28 keys > SMALL_OBJECT_THRESHOLD 8); the comment said
  otherwise. New lookup/small-8-hit-last and small-8-miss time the linear-scan path on an 8-key object.
- mutation/merge-26-into-54-occupied: JSON.MERGE's per-key entry(&str) + overwrite into an object that already
  holds every key (ivalue_manager.rs merge()).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
fcostaoliveira and others added 7 commits November 26, 2026 11:14
…ly reference to a freshly parsed document (the string-cache removal the batch drop cannot see)
…ache reinit RedisJSON's defrag_start does

defrag-copy-yelp keeps the string cache, so every re-intern is a hit and the old
copies stay referenced by the live document: the fresh allocation, the cache's
growth from empty and the stale-copy drop are never timed. The new benchmark parses
a unique document, empties the cache, and times only the defrag. It runs last in
the group because the reinit orphans the live document's cache entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the cache reinit inside the timed section

defrag_start runs once per cycle; a change that moves work into reinit_shared_string_cache
(presizing the new cache) is charged for it here, not hidden as in defrag-reinit-yelp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed mirror

benches/fetch-datasets.sh [--dir DIR] [quick|standard|all|FAMILY...] downloads the
datasets-v1 release assets of redis-performance/json-agent-workspace into DIR
(default benches/datasets, git-ignored), checks each against the pinned list in
benches/datasets.sha256 before unpacking, and skips assets already verified on a
re-run. quick (default): simdjson-data, extras, floatdata, 165 MB download, 0.57 GB
unpacked. GH Archive (public GitHub user data) only with 'all' or by name.
Needs curl, zstd and tar; works with GNU and BSD tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r line

benches/fixtures/refsnp-unsupported-400.ndjson is lines 1-400 of NCBI dbSNP build 157
refsnp-unsupported.json.bz2 (US government work, public domain; 243,806 bytes). It joins
parse, serialise, clone-drop and the memory referee as one IValue per line, the way
JSON.SET stores one key per document. The new benchmarks run after the existing ones in
each group, so the existing rows are measured in the same state as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cargo bench --bench corpus reads IJSON_BENCH_DATASETS (default benches/datasets) and,
per file and one key per document (per NDJSON line), times parse (deserialize_compact_objects
into an empty string cache), drop of the last references, compact serialise and clone, after
a memory table of retained bytes (counting allocator, string cache reset per file). Without
datasets it prints the fetch command and exits 0. IJSON_BENCH_FILES (paths or * / ? patterns),
IJSON_BENCH_MAX_DOCS (1000) and IJSON_BENCH_MAX_BYTES (4 MiB) bound the work; the default
eight files take about two minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…3% with alignment flags

Three-command quick start (fetch, callpaths, corpus) and criterion baselines for two commits;
group table brought up to date (small-8 lookups, occupied merge, drop-last-ref, the r7/r8
defrag benchmarks, refsnp-400); the refsnp-400 provenance; the corpus bench's knobs; dataset
families with sizes and licence/privacy notes; A/B protocol with Linux pinning, three
interleaved pairs, a 3% noise level, the 64-byte code-alignment RUSTFLAGS for placement-free
comparisons, and the four platform classes to report on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gabsow gabsow left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed at 8eec627. The suite builds in both configurations and runs. But four benchmarks don't time the RedisJSON path they stand for, and two of those are one-line fixes.

  1. clone-drop/clone times the drop again.
    • a80cffb switched it to iter_with_large_drop, as the Bugbot thread says. Then 8eec627 restored b.iter(|| black_box(d.clone())) and removed the comment.
    • Criterion's iter drops each output inside the timed loop. Here clone/yelp takes 21.8 µs, and drop/yelp alone takes 6.2 µs.
  2. The string cache isn't the one RedisJSON uses.
    • init_shared_string_cache(false) creates the unlocked cache. RedisJSON at 9ca1c88 calls init_ijson_shared_string_cache(true) ("Always enable thread-safe cache for ASM support"), so interning or dropping any string longer than 7 bytes takes the mutex.
    • I ran two interleaved pairs of unlocked and locked on an Apple silicon Mac, with short settings. With the lock, array-push-pop-hetero is 25% slower, business-22-hit 18%, object-insert-remove-22 14%, wide-128-hit-long-key and small-8-miss 13%, and parse/compact-objects/yelp 5%. drop/yelp is 18% faster. All of these are well past the README's 2–3% thresholds.
    • The same call is in memory.rs and examples/mem_attribution.rs. The doc comment and the description both say false is what RedisJSON does.
  3. defrag-copy-yelp never moves a string.
    • The clone shares every string with doc, so IString::defrag's intern_with_allocator finds each one in the cache and returns it.
    • RedisJSON's defrag_start calls reinit_shared_string_cache(), so a defrag cycle re-allocates each string.
    • Calling reinit_shared_string_cache() in the setup, with BatchSize::PerIteration, would time that. I tried it: the benchmark runs, and goes from about 43 µs, with a wide spread, to 52.4 µs.
  4. str-append times a cache hit.
    • After the first iteration the field already holds city + " (appended)", so IString::from(s) finds that string in the cache. The value it replaces is the same string, so dropping it frees nothing.
    • RedisJSON's str_append interns a new string on every command and drops the old one.
    • Alternating between two suffixes would make each iteration insert one string and remove one. I tried that too: it goes from 40 ns to 77 ns.

Non-blocking:

  1. parse retained in memory.rs depends on fixture order.
    • It includes the intern table's growth only for the fixture that grows it.
    • With mem_attribution, yelp retains 47,008 bytes when it's the first file and 44,696 when it's second. yahoo2's gap to mem_allocated() goes from 0 to 2,312.
    • An untimed parse of the same fixture first would leave only the document in the number.
  2. CBOR decode retained is measured while doc is alive, so every string is a cache hit. For yelp it's 15,704 bytes, the same as the clone, against 47,008 for the parse. Dropping doc before the decode would count the strings an RDB load allocates.
  3. array-trim-typed-1024-to-512 peaks at 2.2 GB of resident memory at the suite's default settings. object-insert-remove-22 peaks at 12 MB. SmallInput keeps a tenth of each sample's clones alive at once, and LargeInput would cap that.
  4. Under thread_safe, mem_attribution counts short strings as inline. string.rs has no inline form, so yelp's 327 short strings are heap allocations, but the example leaves them out of the unique heap strings.
  5. The README table is missing small-8-hit-last, small-8-miss and merge-26-into-54-occupied.
  6. The business-22-* and object-insert-remove-22 names say 22 keys. The business has 28, as the comment above the lookups says.
  7. CI doesn't build the benches. cargo build and cargo test skip bench targets, so an API change could break them without failing CI. A cargo bench --no-run step in both configurations would catch that.
  8. Some comments point to documents outside this repo, such as docs/USAGE-PATTERN.md and "harness r4". Stating the reason in the comment would help readers here.

CI is green, though it doesn't build the benches (non-blocking item 7).

I built the benches in both configurations, ran --bench memory and the mem_attribution example, and ran the whole timing suite with short settings. Every benchmark completes.

fcostaoliveira and others added 11 commits November 26, 2026 12:30
The datasets-v1 assets are now served from
https://s3.amazonaws.com/benchmarks.redislabs/ijson/datasets-v1 (same files,
same pinned sha256 list). IJSON_DATASETS_MIRROR still overrides the base URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b.iter` drops each output inside the timed loop, so `clone/*` timed the
clone plus the drop of the copy, the cost `drop/*` already measures. The
single-document clones now go through `iter_batched` with `LargeInput`,
which drops the clones after each batch, outside the timer; `LargeInput`
rather than `iter_with_large_drop` (SmallInput) because a tenth of a
sample of 8 KB typed-array clones peaked at 2.3 GB of resident memory.
The key-per-line clone collects its clones into a vector made in setup
and returns it, so they are dropped outside the timer too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RedisJSON at 9ca1c88 calls `init_ijson_shared_string_cache(true)` at
module load ("Always enable thread-safe cache for ASM support"), which
reaches `ijson::init_shared_string_cache(true)`: the cache behind a
mutex. The benches, the memory referee and `mem_attribution` initialised
it with `false`, the unlocked cache, and said that was RedisJSON's
choice. Interning a heap string and dropping its last reference both
take the mutex in RedisJSON, so every path that interns or frees strings
(parse, drop, mutation, lookups that build keys) was timed on a cheaper
cache than the one RedisJSON runs. All four now pass `true`, and the
comments and README say why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The copy shares every string with `doc`, so `IString::defrag`'s
`intern_with_allocator` found each one in the cache and returned it: the
benchmark never moved a string. RedisJSON's `defrag_start` calls
`reinit_shared_string_cache()` before a defrag cycle, so each re-intern
misses and allocates a new copy. The setup now reinitialises the cache
before cloning, with `BatchSize::PerIteration` so each defrag starts from
an empty cache. An untracked check confirmed all 922 long-string
references move after the change and none before (default build; the
`thread_safe` build's `IString::defrag` is the identity).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the first iteration the field already held `city + " (appended)"`,
so `IString::from` found the string in the cache and the value it
replaced was the same string: the benchmark timed a cache hit and a drop
that freed nothing. RedisJSON's `str_append` concatenates the field and
the argument, interns the result into the field's `IString` and drops the
old one, which is the field's last reference. The routine now does the
same through `as_string_mut` and `IString::intern`, alternating between
two suffixes of equal length, so each iteration inserts one string into
the cache and removes one (an untracked allocation count shows 2
allocations and 2 frees per iteration, against 1 and 1 before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`parse retained` in the memory referee, and `retained` in
`mem_attribution`, included the string cache table's growth only for the
fixture that grew it, so a fixture's figure depended on what ran before
it (yelp: 47,008 bytes first, 44,696 second). Both now parse the fixture
once and drop it before the measured parse; in the default build the
table keeps its capacity, so the figure is the document alone and equals
`mem_allocated()` for every bundled fixture. (The `thread_safe` build's
cache shrinks a shard when it empties, so there the table growth stays
in, as the comments say.)

`CBOR decode retained` was measured while the parsed document was alive,
so every decoded string was a cache hit (yelp: 15,704 bytes, the clone's
figure). The document and the stream encoder are now dropped first, so
the decode allocates its strings as an RDB load does.

`mem_attribution` counted strings of up to 7 bytes as inline in both
builds, but the `thread_safe` build's `IString` has no inline form: those
strings are heap allocations there and now count as unique heap strings.
The column is renamed "no heap" (empty and, in the default build, inline
strings), and an exact match prints as 0 rather than -0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`SmallInput` keeps a tenth of each sample's setup values and outputs
alive at once. `array-trim-typed-1024-to-512` runs in about 2 ns, so a
sample holds millions of 8 KB clones: the run peaked at 2.2 GB of
resident memory at the default settings. `retag-on-string-push-1024`
returns 1025-element heterogeneous arrays and peaked at 318 MB.
`LargeInput` keeps a thousandth alive; on an Apple M-series Mac the two
runs now peak at 57 MB and 18 MB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`business-22-{hit,miss}` and `object-insert-remove-22` run on the first
yelp business, which has 28 keys (as the comment above the lookups
already said). They are now `business-28-{hit,miss}` and
`object-insert-remove-28`, both groups assert the key count, and the
comments and README use 28; the merge benchmark's 54 keys are 28 + 26.
The insert/remove comment no longer quotes absolute timings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`cargo build` and `cargo test` skip bench targets, so an API change that
breaks a benchmark would pass CI. The build-and-test job now runs
`cargo bench --no-run` with `--no-default-features` (the configuration
RedisJSON uses) and with `--features thread_safe`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Some comments pointed to documents that are not in this repository (a
usage-pattern document, harness revision numbers): a reader here could
not follow them. The callpaths header now lists the groups and the
RedisJSON sources their argument shapes come from, the section headings
drop their numbering, the Cargo.toml comments say what each bench target
is, and the NUMINCRBY and drop comments say why they avoid a setup clone
(a clone's layout is set by the clone code, so a change to `clone` would
move them).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mirror now serves every family publicly, so the notes state the licence
position (no data licence stated by simdjson-data, float-data and Pison; GH
Archive's public GitHub user data) instead of asking users not to publish
copies, and keep the advice not to commit GH Archive data to a repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread benches/callpaths.rs Resolved
Comment thread benches/corpus.rs Resolved
Comment thread benches/fetch-datasets.sh Resolved
… fetch re-checks unpacked files

- typed/build-f64-push-1024 and typed/build-i64-try-extend-16k returned the
  array from b.iter, so its drop was timed with the build. They now use
  iter_batched with LargeInput, as parse and clone do, so the array is
  dropped after the batch.
- The corpus bench's counting allocator now counts a realloc as an
  allocation, as mockalloc (used by --bench memory) records it, so the two
  tables' allocation columns agree.
- fetch-datasets.sh: the verification mark now lists the files an asset
  unpacked, and a re-run downloads the asset again if any is missing. Marks
  written before this change (sha256 only) also cause a re-fetch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 81f8ccb. Configure here.

Comment thread benches/callpaths.rs Resolved
stream-encode-yelp-fresh-encoder and stream-decode-yelp returned only the
payload or value, so the StreamEncoder (its string table) and the
StreamDecoder (its definition table and the IString references it holds)
were dropped inside the timed routine. Both are now handed back with the
output and dropped after the batch, as every other output in the suite is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every pull request now runs .github/scripts/memory-gate.sh: the PR's memory
referee (benches/memory.rs) measures the library at the base branch's tip,
fetched when the job runs, and the PR, each built in its own target dir.
Every retained and peak byte count, ijson_mem_allocated and size_of of the
core types is compared per fixture, and the job fails if any grows by more
than 5 % (MEMORY_GATE_MAX_PCT). The default build's counts are exact and
repeat, so it runs once per side; the thread_safe build's sharded cache
takes a random hash seed (up to ~13 % run-to-run on the 1.3 KB fixture), so
the gate uses the median of 5 runs per side, which repeats within ~1.5 %.
A base that predates the harness takes this checkout's Cargo.toml.

Checked: three clean runs against master pass (default build unchanged,
thread_safe medians within 1.25 %); an object layout padded by two
entries fails with 51 figures above 5 %.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gabsow gabsow left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Re-reviewed at 0fc1cd4. Every item from my last review is fixed, and I checked each one. Approving, with some non-blocking notes: three on the new memory gate, and four on the benches.

Fixed, as measured on an Apple silicon Mac:

  1. clone-drop/clone times the clone only: clone/yelp is now 15.5 µs, and drop/yelp is 5.0 µs.
  2. The benches, memory.rs and mem_attribution all use the locked cache, and the comments say so.
  3. defrag-copy-yelp empties the cache in setup, so every string moves. It now takes 55.9 µs.
  4. str-append alternates two suffixes, so each iteration interns one string and frees one. It takes 88 ns.
  5. In the default build, parse retained equals mem_allocated() for every fixture, and mem_attribution prints the same numbers in either file order.
  6. CBOR decode retained for yelp is now 41,896 bytes, up from 15,704.
  7. The trim benchmark peaks at 57 MB of resident memory, down from 2.2 GB.
  8. Under thread_safe, mem_attribution counts only yelp's 21 empty strings as having no heap allocation.
  9. The README table, the 28-key names, the CI bench builds and the comments are fixed too.

The new code works:

  • All 71 callpaths benchmarks run once in both builds, and cargo fmt --check passes.
  • --bench corpus exits 0 without datasets. I also ran it over a local directory of the bundled yelp and RefSNP files, using a glob in IJSON_BENCH_FILES and a duplicate file name. It runs, and it labels the duplicate by its parent directory.
  • I ran fetch-datasets.sh under macOS's bash 3.2 against a local file:// mirror, with no arguments and with named families. It fetches and verifies, skips verified assets on a re-run, and re-fetches an asset after one of its files is deleted.
  • Every asset in datasets.sha256 is on the S3 mirror, and the quick and standard download sizes match the README.
  • The memory gate passes in CI.

On the memory gate (0fc1cd4):

  1. It commits .github/scripts/__pycache__/memory_gate.cpython-313.pyc. That's Python's compiled cache from a local run. Removing it and adding __pycache__/ to .gitignore would keep it out.
  2. It allows 5 % growth in the default build too. Its counts repeat exactly there, and the README's A/B protocol asks for memory to stay identical unless a change declares otherwise. A 0 % limit for the default build, keeping 5 % for thread_safe, would match that.
  3. It can blame a PR for changes on the base branch.
    • It compares HEAD with the base branch's tip at run time. In CI, HEAD is the merge commit, so the two agree until the base moves. A re-run keeps the old merge commit but takes the new tip.
    • Run locally, as the README suggests, HEAD is the branch itself. So anything merged into master since the branch point counts for or against it.
    • Measuring the base at the commit HEAD was built on would avoid both. In CI that's the merge commit's first parent, HEAD^1, which needs fetch-depth: 2 on the checkout. Locally it's git merge-base HEAD origin/$BASE_REF.

On the benches:

  1. parse/compact-objects/* mostly times cache hits.
    • Within a batch, every parse after the first finds its strings in the cache. A JSON.SET of new string values takes the miss path instead.
    • I timed a yelp parse on its own, dropped outside the timer: 58.6 µs with an empty cache, and 47.8 µs with another copy alive. compact-objects/yelp reads 48.0 µs, so it's the warm case. corpus-parse on the same file reads 59.7 µs.
    • I missed this last time. It isn't blocking: corpus-parse covers the cold path once the datasets are fetched, and keys that share a schema do take the warm path. Still, the README table could say that parse is the warm case, and a cold variant could sit beside it, as drop-last-ref does for drops.
  2. array-trim-typed-1024-to-512 only covers a trim from index 0.
    • RedisJSON's arr_trim rotates the slice left by start, then truncates. With start at 0 the rotate does nothing, so the benchmark is a length store and reads 1 ns.
    • Keeping the middle half instead, with rotate_left(256) on as_mut_slice() and then truncate(512), takes 122 ns. Capping an appended list to its last N elements takes that path.
  3. drop-last-ref/floats-1024 mostly times the timer. It reads 32 ns, against 15 ns for drop/floats-1024. A typed array holds no strings, so both do the same work. The gap is most likely the two Instant calls per iteration.
  4. parse retained means two things. For yelp it's 42,392 bytes in --bench memory, which leaves out the table growth, and 47,008 bytes in the corpus table, which resets the cache per file and so counts it. Different column names would stop anyone comparing the two tables.

CI: every job passes, including the memory gate. Bugbot hadn't finished on this commit when I posted.

fcostaoliveira and others added 4 commits November 26, 2026 13:44
.github/scripts/__pycache__/memory_gate.cpython-313.pyc came from a local run
of the memory gate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d in

The gate compared HEAD with the base branch's tip. In CI, HEAD is the merge
commit, which a re-run keeps while the tip moves; run locally, HEAD is the
branch, so anything merged into the base since the branch point counted
for or against it. Both sides are now built from the tip fetched when the
gate runs: the tip itself, and the tip with HEAD merged in (no commit), with
the merged tree's harness. Changes that reached the base are on both sides,
so only HEAD's own changes count, and the comparison is still always against
the current tip. The checkout fetches full history for the merge; a HEAD that
does not merge cleanly fails the gate with a message to update the branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orpus column

- parse/compact-objects-cold/*: each parse runs with no other copy alive, so
  every string is inserted into the cache (the JSON.SET of new string
  values); only the parse is timed. compact-objects stays as the warm case
  (within a batch the strings are already cached, as for keys sharing a
  schema) and the README says so.
- mutation/array-trim-typed-1024-middle-512: ARRTRIM keeping the middle
  half, through arr_trim's rotate_left then truncate. The trim from index 0
  only stores a length.
- clone-drop/drop-last-ref skips floats-1024: a typed array holds no
  strings, so its last-reference drop is drop's work, and at ~15 ns the two
  Instant reads per iteration dominated it.
- The corpus memory table's column is 'parse retained incl. string table':
  it resets the cache per file, so it counts the table growth that
  --bench memory's 'parse retained' leaves out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default build's counts come from a counting allocator and repeat
exactly, so any change is real; the A/B protocol asks for memory to stay
identical unless a change declares otherwise. Its limit is now 0 %
(MEMORY_GATE_MAX_PCT_DEFAULT). The thread_safe build keeps +5 % on the
median of 5 runs (MEMORY_GATE_MAX_PCT_TS), since its sharded cache's random
hash seed moves its counts between runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fcostaoliveira
fcostaoliveira merged commit 35d514c into RedisJSON:master Nov 26, 2026
8 checks passed
fcostaoliveira added a commit to fcostaoliveira/ijson that referenced this pull request Nov 26, 2026
…tring-in-register

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fcostaoliveira added a commit to fcostaoliveira/ijson that referenced this pull request Nov 26, 2026
…drop-single-probe

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fcostaoliveira added a commit to fcostaoliveira/ijson that referenced this pull request Nov 26, 2026
…y-str-without-intern

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fcostaoliveira added a commit to fcostaoliveira/ijson that referenced this pull request Nov 26, 2026
…py-table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fcostaoliveira added a commit to fcostaoliveira/ijson that referenced this pull request Nov 26, 2026
…obe-before-intern

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fcostaoliveira added a commit to fcostaoliveira/ijson that referenced this pull request Nov 26, 2026
…rays-no-boxing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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