Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Contributing

How to build, test and benchmark compara, and the performance gate every change passes.

Bug reports and pull requests are welcome. For anything larger than a fix, open an issue first so we can agree on the approach.

Build and test

cargo build --release
cargo test --release
cargo fmt --check
cargo clippy --all-targets --all-features -- -D warnings

A cold build takes about twenty seconds. The tests assert one result contract across every engine and every input format, cell for cell: a change that makes two engines, or a CSV and a Parquet copy of the same rows, disagree fails them.

The toolchain

rust-toolchain.toml names the rustc that CI, the perf gate, the benchmarks and the release workflow build with, and rustup installs it for any cargo run in the checkout (cargo +stable ... builds with another). A new rustc moves instruction counts with no change to the code, so the perf gate, the benchmark results and each release’s notes name the rustc that built every binary they measure or ship; scripts/buildinfo.py <binary> reads it from a Linux binary. Compare counts from one compiler only.

The version moves in a pull request that changes nothing else; Dependabot opens one when a new rustc is out. Its perf gate builds both sides with the new rustc, then the head with the base’s, and prints what the compiler alone moves under “The compiler alone”; that table goes in the pull request and in the next CHANGELOG. rust-version in Cargo.toml (the oldest Rust that builds compara, checked by ci’s msrv job) does not move with it.

Test data

cargo run --release --bin compara-gen-data -- --rows 1m --out-dir data
cargo run --release --bin compara-gen-data -- --rows 1m --out-dir data --format parquet
compara compare data/1m_a.csv data/1m_b.csv -k account_id,txn_id -i updated_at

compara-gen-data writes a deterministic 20-column pair keyed on (account_id, txn_id), as CSV, newline-delimited JSON or Parquet, from one recipe. Money is carried in integer cents and drifted as integers, so the files are byte for byte reproducible:

DriftShare of rows
status changed3.0%
amount changed (+12.34)1.5%
balance changed (+1%, half up)1.5%
value_date blanked0.3%
updated_at changed100% (excluded with --ignore)
rows only in B0.10%
rows only in A0.10%
duplicate keys0.01% per file

The small files in tests/fixtures/ are written by pyarrow, not by this project (a reader tested only against its own writer’s files tests nothing); tests/fixtures/README.md says what each one is for, and scripts/ holds the scripts that write them.

Benchmarks

cargo run --release --features bench --bin compara-bench -- --rows 1m --engine turbo --out-dir bench

compara-bench runs the comparison in a child process so peak RSS is measured honestly, records generation time, wall time, throughput, report size and counts, and fails when a scale exceeds its budget. Compare numbers from one machine and one sitting only.

The performance gate

Every pull request counts the instructions compare takes, for each engine, on 50k and 200k generated rows a side, and with turbo on 200k rows of NDJSON written compactly (--format ndjson) and as Python’s json.dumps writes them by default (each line loaded and dumped again: , and : ), at its head and at its base:

python3 scripts/perf_gate.py --head target/release/compara --base /path/to/base/compara \
  --small 50k_a.csv 50k_b.csv --large 200k_a.csv 200k_b.csv \
  --json 200k_a.ndjson 200k_b.ndjson --json-spaced 200ksp_a.ndjson 200ksp_b.ndjson \
  -- -k account_id,txn_id -i updated_at

It fails when a count rises more than 5% over the base’s, when four times the rows cost more than 5.5 times the instructions (linear and n log n work sits at 4.0-4.2, quadratic at 16), or when the spaced NDJSON costs more than 1.1 times the compact in the head (about 1.04 when each spaced row is read as a compact one is; about 2 when it is not). A count repeats to a few hundredths of a percent where a time on a shared runner varies by two or three times, so the bounds can be tight. scripts/icount.py counts one command: with the processor’s counter where the kernel offers one, else with valgrind (exact, about 25 times slower); compare counts from one counter only. A change that is meant to cost more says so in its description.

Diagnostics

variableeffect
COMPARA_PHASES=1print where the time went, phase by phase
COMPARA_PRINT_PEAK_RSS=1print peak memory at exit (Linux)
COMPARA_MEMORY=<size>the memory budget, as --memory
COMPARA_BACKTRACE=1a backtrace on panic

Layout

src/main.rs               argument parsing and exit codes
src/lib.rs                the library's public surface
src/contract.rs           the result contract
src/options.rs            runtime parameters and engine names
src/engine.rs             compare() entry point and the engine registry
src/engine/turbo.rs       the byte-level engine: threading, the index, the join
src/engine/turbo/         field packing, SWAR and AVX2 scans, CSV/JSON readers, the Parquet reader
src/engine/pqdiff.rs      the columnar path for a Parquet pair
src/engine/sortmerge.rs   external sort and merge join
src/engine/native.rs      csv-crate parse, in-memory join
src/report.rs, report.html  the HTML report and its embedded template
src/profiles.rs           compara.toml profiles
src/gendata.rs            the test data generator (and src/gendata/parquet.rs, its writer)
src/bin/                  compara-gen-data and compara-bench
tests/                    the contract, every engine and format, out-of-memory behaviour

Releasing

  1. Bump version in Cargo.toml and add a CHANGELOG.md entry on main.
  2. Actions → release → Run workflow with that version. The run checks the version, builds every target, tags v<version>, creates the GitHub release and publishes to each registry that is switched on.

Registries are switched on per repository with Actions variables, once the account and trusted publisher exist:

variablepublishes totrusted publisher to configure
PUBLISH_CRATES=truecrates.iocrate compara, workflow release.yml
PUBLISH_NPM=truenpm (compara + one package per platform)each package, workflow release.yml
PUBLISH_PYPI=truePyPI (platform wheels)project compara, workflow release.yml, environment release
HOMEBREW_TAP=owner/homebrew-tapHomebrew formulasecret TAP_TOKEN with write access to the tap
SCOOP_BUCKET=owner/scoop-bucketScoop manifestthe same TAP_TOKEN

Re-running the workflow for a version that already exists rebuilds its files and publishes it to any registry that doesn’t have it yet.


Made from CONTRIBUTING.md.