Repository navigation
Compare jiter with serde_json over the json-cases corpus - #266
Conversation
Adds `crates/jiter/tests/json_cases.rs`, which parses every document in the json-cases corpus with both `JsonValue::parse` and `serde_json`, and requires the two to agree on whether it is valid JSON, on the value it decodes to, and on the error message when they reject it. The places they legitimately differ are listed in `known_difference()` with a reason, and nothing else is allowed: jiter's 4300 digit cap on numbers, its recursion limit of 200 against serde_json's 128, and the two errors where the message matches but the position doesn't (serde-rs/json#1083, #130). A second test covers `allow_inf_nan`, the one place jiter deliberately parses more than serde_json does: the NaN/Infinity extension must be purely additive, so everything serde_json accepts still decodes to the same value. The corpus is a separate checkout whose `cases/` is a build artifact, so both tests skip themselves when it isn't there; `../json-cases` is used by default and `JSON_CASES` overrides it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KLR7FhfVNh2Qmd8WS7NwHD
`cases.json` records, under `similar`, the groups of documents that are one another's re-spellings — the same document re-indented, or with its strings escaped differently. `similar_cases_agree` holds jiter to what that promises: every member of a group decodes to the same value, or, where the document is malformed, they are all rejected (only the error position may vary). Each group is checked with `allow_inf_nan` off and on, which is also what makes the `python-inf-nan` groups compare values rather than agree on rejecting them. 418 groups, 863 documents. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
Merging this PR will improve performance by 18.23%
Performance Changes
Tip Curious why this is faster? Comment Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
`json_cases.rs` in benches/ reads every case into memory and parses the lot in one iteration, swallowing the errors: a mixed workload of ~2800 documents, most of them small and over half malformed, where every benchmark in main.rs is a single well formed document of one shape. It is the only one that measures the error paths. The corpus is timed as a whole and then once per `tags` entry of cases.json, which is what says roughly where a change landed — the string scanner, number decoding, the recursion, the whitespace loop or the failure path. Category would have been the wrong axis: `deep-complete/` holds the deep documents and their `--indented` twins, and timing those measures whitespace. The index loader moves to tests/corpus/mod.rs, shared by the test and the benchmark. The tests now require the corpus rather than skipping when it is missing, so a checkout without it can't quietly pass the suite; JSON_CASES_SKIP opts out, and CI builds the corpus for `test` and skips it for `test-latest-deps`, which is about resolving dependencies fresh. The benchmark still registers nothing when the corpus is absent, so `cargo bench` and the CodSpeed job are unaffected. The clone URL in the docs pointed at pydantic/json-cases, which 404s; the repo is public at samuelcolvin/json-cases. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
Tracking the default branch means a corpus commit can turn this repository's CI red without a change here; the pin makes the corpus move a deliberate bump. fa6c17f is the tip of main today, the commit that added `size` and `tags`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
CI checks the corpus out at $GITHUB_WORKSPACE/json-cases, which puts its own crate inside this workspace; cargo then refuses to build it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
The bench job now checks out and builds json-cases too, so the json_cases benchmarks register there instead of being silently absent. The pin moves to a workflow level JSON_CASES_REF so the bench job and the test job can't drift onto different revisions of the corpus — which would make the benchmark numbers incomparable as well as the tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
They were far longer than what they introduce; the commands they spelled out are in benches/README.md and in the message the tests panic with. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
3ca76ae to
986e44c
Compare
They are the local comparison baseline; CodSpeed tracks jiter's own history, and serde_json is pinned in Cargo.lock, so instrumenting it buys a line that doesn't move and doubles the run. `cfg(codspeed)`, which cargo-codspeed sets, compiles them out the way monty leaves its CPython benchmarks out of CI. Registered under codspeed: main.rs 44 benchmarks instead of 60, json_cases 13 instead of 26. A plain `cargo bench` still runs both halves. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UFzFCpVcjJDsbtgQZNvhFo
|
@codspeedbot explain why the benchmarks keep jumping around by as much as 17%! |
Dug into the runs. The instrument isn't noisy — two separate 1. The 17% and 10% come from commit 5f0b0bf, not from the runner
The flamegraphs say where it went.
That 2.2 µs drop is the entire 2.1 µs "improvement". jiter's own frames barely move. Criterion runs every benchmark in one process, so dropping 16 serde benchmarks from This is worth knowing but not worth reverting: it's a one-time re-baseline. Once this merges, 2. The background ±10% is the runner CPU
Dependency drift, the third cause we hit on #264, is gone now that What would actually fix this
I haven't changed anything in the PR — say the word and I'll wire up either of those. Summary
Learnings updated. See what CodSpeed remembers about this repository. Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot. |
Adds
crates/jiter/tests/json_cases.rs, which parses every document in the json-cases corpus with bothJsonValue::parseandserde_json, and requires the two to agree on whether it is valid JSON, on the value it decodes to, and on the error message when they reject it.The places they legitimately differ are listed in
known_difference()with a reason, and nothing else is allowed: jiter's 4300 digit cap on numbers, its recursion limit of 200 against serde_json's 128, and the two errors where the message matches but the position doesn't (serde-rs/json#1083, #130).A second test covers
allow_inf_nan, the one place jiter deliberately parses more than serde_json does: the NaN/Infinity extension must be purely additive, so everything serde_json accepts still decodes to the same value.The corpus is a separate checkout whose
cases/is a build artifact, so both tests skip themselves when it isn't there;../json-casesis used by default andJSON_CASESoverrides it.Claude-Session: https://claude.ai/code/session_01KLR7FhfVNh2Qmd8WS7NwHD