Performance
aq is faster than jq, gojq, and jaq on almost every workload over real-sized inputs: across the benchmark suite it takes 0.35x jq's time and 0.52x jaq's. Large JSONL is evaluated on every core, so record filters run 4 to 10 times faster than any of them. Format conversion is 3 to 140 times faster than yq, dasel, and Miller. The exception is tiny inputs, where process startup decides and aq can be up to 0.5 ms slower than jq. All numbers were measured on one shared 48-thread Linux machine (WSL2), so expect 5 to 15% noise between runs.
The dev shell (default.nix) provides every tool compared here: jq, gojq, jaq, yq, dasel, Miller, hyperfine, perf, and GNU time.
Benchmark suite
scripts/large_benchmark.py generates seeded datasets (1k, 20k, and 150k records as JSON, JSONL, CSV, YAML, and TOML, plus deeply nested documents) and times about 40 cases against jq 1.8.2, gojq, jaq, yq, and optionally a jq master build. Every aq result is checked against jq's output; the other tools are timed only. The full tables, with peak memory, are in benchmarks/large-benchmark.md (1k, 20k, and fixed cases) and benchmarks/large-benchmark-150k.md.
cargo build --release
python3 scripts/large_benchmark.py --sizes small,medium,-
python3 scripts/large_benchmark.py --sizes large \
--json-out benchmarks/large-benchmark-150k.json \
--markdown-out benchmarks/large-benchmark-150k.mdEach run takes 2 to 3 minutes. --only narrows the cases, and --jq-master-binary adds a jq master column.
| Size | Pairs | aq/jq | aq/gojq | aq/jaq |
|---|---|---|---|---|
| small (1k records, ~0.4 MB) | 42 | 0.56x | 0.43x | 0.73x |
| medium (20k records, ~7 MB) | 42 | 0.21x | 0.24x | 0.39x |
| large (150k records, ~55 MB) | 9 | 0.24x | 0.26x | 0.34x |
| startup and deep nesting | 7 | 0.78x | 0.56x | 0.78x |
| all | 100 | 0.35x | 0.33x | 0.52x |
Ratios are geometric means; below 1.00x means aq is faster. aq was faster than jq in 93 pairs, than gojq in 97 of the 98 it could run (gojq has no -S), and than jaq in 95, with no output mismatches. Against yq, on the 31 pairs yq could run, aq took 0.12x the time.
The biggest wins over jq are walk (0.05x), with_entries (0.10x), and counting scalar paths (0.11x). The losses are startup-bound: -n 1 and tiny inputs (1.4x to 1.5x), a 1k-record reduce that appends to an array (1.4x), 1k-row CSV (1.2x), and three deep-nesting cases within 5% of jq.
Format conversion
The format_benchmark shell script runs hyperfine on the 20k-record datasets (run the benchmark suite once first to generate them) and writes benchmarks/format-benchmark.md. It is timing only; CSV shapes differ, since aq reads rows as arrays and the others as objects.
| Case | aq | jq | gojq | jaq | yq | dasel | Miller |
|---|---|---|---|---|---|---|---|
startup (-n 1) | 2.1ms | 1.9ms | 2.4ms | 2.2ms | 4.5ms | ||
| JSONL select | 11ms | 60ms | 101ms | 47ms | 257ms | ||
| JSON to YAML | 176ms | 1.28s | 1.31s | ||||
| YAML to JSON | 194ms | 1.26s | 0.89s | ||||
| TOML to JSON | 144ms | 19.8s | 0.59s | ||||
| CSV to JSON | 19ms | 1.73s | 0.33s | 66ms |
Before and after
What the latest round of work changed, on the 20k-record (7 MB) dataset. "Before" is the build that preceded it; times are hyperfine means.
| Case | Query | Before | Now | jq 1.8.2 | jaq 3.1 |
|---|---|---|---|---|---|
| parse | length | 73ms | 30ms | 119ms | 44ms |
| compact | -c . | 102ms | 37ms | 161ms | 74ms |
| sort keys | -S -c . | 214ms | 63ms | 185ms | 79ms |
| reduce into object | reduce .[] as $r ({}; .[$r.addr.city] += 1) | 119ms | 40ms | 175ms | 61ms |
| tostring | .[] | .addr | tostring | 117ms | 42ms | 125ms | 61ms |
| arithmetic | map(.age * 2 + .score / 3 - 1) | 97ms | 35ms | 149ms | 62ms |
| group_by | group_by(.addr.city) | map(...) | 106ms | 41ms | 152ms | 89ms |
| walk | walk(if type == "string" then ascii_downcase else . end) | 206ms | 98ms | 2.07s | 682ms |
| JSONL select | select(.age > 85) | .id | 48ms | 11ms | 60ms | 47ms |
| deep round trip | map(tojson | fromjson) on 1,000-deep trees | 290ms | 71ms | 231ms | 107ms |
| startup | -n 1 | 1.5ms | 2.1ms | 2.0ms | 1.8ms |
On the 150k-record JSONL file (55 MB), select(.age > 85) | .id takes 43ms against jaq's 346ms and jq's 433ms, at 128 MB peak memory (68 MB on one thread).
What makes it fast
- mimalloc. The global allocator is mimalloc, which halves the time of allocation-heavy work such as parsing and object construction. It costs about 0.5 ms of startup, mostly committing its first memory arena.
- Parallel JSONL. JSONL input over 4 MB is split into chunks of whole lines that are parsed and evaluated on every core, with results written in input order. It applies when the query treats each input on its own (no
input,inputs,debug,-s, or-n) and the output is JSON. - Shared values. Arrays and objects are reference-counted and copied only when they are modified while shared. Passing a value through
., a variable, orreducecosts a pointer copy, not a deep clone; so do update-assignments like.[$k] += 1on areduceaccumulator. - Cheap scopes. Variables live in a persistent list and function bodies and arguments are shared, so binding
$xor calling a function copies pointers, not scopes or syntax trees. - In-place accumulation. When
+owns an unshared left operand, it extends it in place.reduce ... (. + [$i])and string or object accumulation run in linear time instead of quadratic. - Direct parsing. JSON is deserialized straight into
aq's value type, with no intermediate tree. Decimals that a double prints back exactly are stored as doubles; only the rest keep their source text. - Streaming evaluation. JSON and JSONL inputs are evaluated one value at a time as they are parsed, and results are written as they are produced, so memory stays flat on record streams.
- No teardown. Inputs and results larger than 1 MB are left for the OS to reclaim at exit instead of being freed piece by piece.
Object keys are hashed with foldhash rather than the standard library's SipHash. Calls in tail position run in the caller's loop instead of on a new stack frame, so def f: if . == 0 then . else (. - 1 | f) end; 50000 | f takes 7 ms (jq 9 ms, jaq 12 ms). Other recursion costs about 3 KB of stack per level.
jq's test corpus
scripts/jq_upstream_benchmark.py times every harvested jq success case that both tools pass, one warmup and three measured runs each. Raw results are in benchmarks/jq-upstream-benchmark.md and the matching .json file.
python3 scripts/jq_upstream_benchmark.py \
--jq-binary "$PWD/tmp/jq-master/build/install-pure/bin/jq"Use an absolute jq path; the harness changes directories while it runs module cases. The comparison binary is a local jq master build (69785bf).
| Metric | Value |
|---|---|
| Harvested cases | 908 |
| Compared | 862 |
| aq faster / jq faster / about equal | 9 / 834 / 19 |
| Sum of medians, jq / aq | 1.640s / 2.203s |
| Median aq/jq | 1.37x |
| Geometric mean aq/jq | 1.37x |
Most of these cases take 1 to 3 ms, so process startup decides them, and this is where mimalloc's startup cost shows: before it, the same corpus measured 0.93x to 0.99x. The harness runs inside the dev shell, whose large environment also makes mimalloc's scan for MIMALLOC_* options slower than in a typical shell. 46 cases are uncomparable, mostly because the local jq build predates newer upstream tests and fails them as well.
The heavy cases still favor aq, for example a strptime/mktime/strftime round trip over 24,455 dates; see the report for the full list.