Skip to content

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.

bash
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.md

Each run takes 2 to 3 minutes. --only narrows the cases, and --jq-master-binary adds a jq master column.

SizePairsaq/jqaq/gojqaq/jaq
small (1k records, ~0.4 MB)420.56x0.43x0.73x
medium (20k records, ~7 MB)420.21x0.24x0.39x
large (150k records, ~55 MB)90.24x0.26x0.34x
startup and deep nesting70.78x0.56x0.78x
all1000.35x0.33x0.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.

CaseaqjqgojqjaqyqdaselMiller
startup (-n 1)2.1ms1.9ms2.4ms2.2ms4.5ms
JSONL select11ms60ms101ms47ms257ms
JSON to YAML176ms1.28s1.31s
YAML to JSON194ms1.26s0.89s
TOML to JSON144ms19.8s0.59s
CSV to JSON19ms1.73s0.33s66ms

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.

CaseQueryBeforeNowjq 1.8.2jaq 3.1
parselength73ms30ms119ms44ms
compact-c .102ms37ms161ms74ms
sort keys-S -c .214ms63ms185ms79ms
reduce into objectreduce .[] as $r ({}; .[$r.addr.city] += 1)119ms40ms175ms61ms
tostring.[] | .addr | tostring117ms42ms125ms61ms
arithmeticmap(.age * 2 + .score / 3 - 1)97ms35ms149ms62ms
group_bygroup_by(.addr.city) | map(...)106ms41ms152ms89ms
walkwalk(if type == "string" then ascii_downcase else . end)206ms98ms2.07s682ms
JSONL selectselect(.age > 85) | .id48ms11ms60ms47ms
deep round tripmap(tojson | fromjson) on 1,000-deep trees290ms71ms231ms107ms
startup-n 11.5ms2.1ms2.0ms1.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, or reduce costs a pointer copy, not a deep clone; so do update-assignments like .[$k] += 1 on a reduce accumulator.
  • Cheap scopes. Variables live in a persistent list and function bodies and arguments are shared, so binding $x or 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.

bash
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).

MetricValue
Harvested cases908
Compared862
aq faster / jq faster / about equal9 / 834 / 19
Sum of medians, jq / aq1.640s / 2.203s
Median aq/jq1.37x
Geometric mean aq/jq1.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.

Structured querying, rewriting, and Starlark scripting across common data formats.