| Harness | Question it answers | Runs |
|---|---|---|
perf_proof.py |
Did my changeset make bazel-diff faster or leaner? | by the change's author, locally (make perf-proof) |
tango_compare.py |
How does bazel-diff compare with Uber's Tango on the same workloads? | nightly |
cache_probe_bench.py |
Is remote-cache probing sound and a win over hashing? (experiment) | nightly |
partial_graph_bench.py |
Is serve --partialGraph exactly as accurate and faster? |
nightly |
A PR that claims to make bazel-diff faster or to use less memory proves it with this harness and
nothing else: no ad-hoc time runs, no flamegraph screenshots as the evidence. The harness takes
the changeset, builds a bazel-diff binary from each side, runs both on Bazel workspaces of several
sizes, and reports what the bazel-diff process cost on each side, with a statistical verdict and
a correctness check. Attach perf-proof-summary.md to the PR.
# HEAD against its merge-base with master, on small + medium + large, 5 interleaved iterations.
make perf-proof
# The same through the script, with explicit revisions, a patch series, or the uncommitted tree.
python3 tools/perf/perf_proof.py --base v70.0.0 --candidate my-branch
python3 tools/perf/perf_proof.py --base master --patch 0001-faster.patch --patch 0002.patch
python3 tools/perf/perf_proof.py --candidate WORKTREE
# More power on one size; a real repository alongside the synthetic ones; prebuilt binaries.
python3 tools/perf/perf_proof.py --workload large --iterations 10
python3 tools/perf/perf_proof.py --repo-url https://github.com/bazelbuild/bazel-skylib.git --repo-clone-args --depth=50
python3 tools/perf/perf_proof.py --base-binary ~/Downloads/bazel-diff-70.0.1 --candidate-binary bazel-bin/src/bazel-diff
# Smoke profile (tiny workload, 2 iterations: checks the setup, proves nothing), and the noise floor.
make perf-proof-quick
python3 tools/perf/perf_proof.py --aaThe default threshold comes from that noise floor: an A/A run (the same binary on both sides,
--aa) on the small workload moves bazel-diff's CPU median by about 4% between sides at five
iterations, with p far above 0.05, so differences under 5% are reported as unchanged. A change
whose effect is smaller than that needs a bigger workload (--workload large), where the
process's own work dwarfs the fixed costs, or more iterations.
Requirements: git, a bazel/bazelisk binary (--bazel for the measured workspaces,
--build-bazel for the builds; both default to bazel on PATH), Python 3.9+, standard library
only. The harness checks the two sides out, in turn, into a build worktree under
~/.cache/bazel-diff-perf-proof/<repo-key>/ (--build-dir to move it) with its own Bazel output
base, and builds them with --config=release, the flags releases ship with (--builder cargo
for cargo build --release instead). Builds run with --nohome_rc as well, always: a ~/.bazelrc
that streams to a build event service or changes compilation flags must not shape the binaries
being compared. Your checkout is never modified. The build directory
persists between runs, so only the first run on a machine pays a cold build (a fresh output base
fetches and compiles every crate and the toolchain: well over ten minutes); after that each side
is an incremental build of a few seconds. --fresh-build discards it. Budget a few minutes per
workload for the measurement itself.
Per workload and iteration, each side runs the README recipe split into four stages:
| Stage | Command | Why it is its own stage |
|---|---|---|
generate-hashes @base, cold |
git checkout base; bazel shutdown; generate-hashes |
what a CI job pays: server start, full graph load, hashing |
generate-hashes @base, warm |
generate-hashes again |
Bazel's share is smallest here, so bazel-diff's own cost is clearest |
generate-hashes @head --depEdgesFile |
git checkout head; generate-hashes -d deps.json |
dependency tracking on: the memory-heavy variant |
get-impacted-targets |
get-impacted-targets -d deps.json |
pure bazel-diff: parsing, diffing, closure |
For every stage the harness records, from the kernel's accounting of the reaped child
(os.wait4), the bazel-diff process tree's CPU time (user + system, with the two shown
separately so a change that trades syscalls for computation is visible) and peak RSS, plus its
wall time, and the Bazel server's CPU delta over the stage (read from the server pid; the
server is a daemon outside the process tree, so it is reported separately rather than mixed in).
Every Bazel invocation the harness makes, builds included, runs with --nohome_rc, and that is
not configurable: a run that a developer's ~/.bazelrc can shape is not reproducible, so
--bazel-startup-options and --build-bazel-startup-options only add options after it and
--home_rc is refused. --generate-arg adds flags such as --useCquery to every
generate-hashes.
Base and candidate run back to back in every iteration, and the order flips each iteration, so
drift over the run (thermal throttling, page cache, other processes) lands on both sides. One
untimed warm-up flow runs first so Bazel's one-off fetches (bazel_tools) are not timed.
Per workload, stage and metric the harness compares medians and runs a two-sided Mann-Whitney U test over the per-iteration samples (exact for small samples). Lower is always better.
| Verdict | Meaning |
|---|---|
| improved / regressed | the median moved by at least --threshold percent (default 5) and p < --alpha (default 0.05) |
| unchanged | the median moved by less than the threshold |
| inconclusive | the median moved by more than the threshold but the samples do not confirm it: rerun with more --iterations |
| insufficient data | too few iterations for any outcome to reach α (two iterations cannot; four can at α=0.05) |
The headline folds the verdicts of the verdict metrics (--verdict-metrics, default bazel-diff
CPU and peak RSS) over every workload and stage: any regression makes it REGRESSED (a change
that helps one size and hurts another is not a proven improvement), otherwise any improvement makes
it IMPROVED, otherwise NO CHANGE, INSUFFICIENT DATA or INCONCLUSIVE. Wall time and
Bazel server CPU are reported for context but do not drive the headline by default: on the
generate-hashes stages wall time is mostly bazel query, whose variance has nothing to do with
the change.
Correctness is part of the proof. Every run's generate-hashes outputs (both revisions and the
dependency edges) must be byte-identical to the first base run's, and the impacted set must match
label for label. A mismatch is called out at the top of the report and fails the harness
(exit 2) unless --allow-output-diff says the change is meant to move the hashes, in which case
the report still shows which outputs moved. --fail-on-regression (exit 3) and
--require-improvement (exit 4) turn the headline into an exit status for scripting.
The synthetic presets are the layered genrule workspaces of
gen_project.py that the nightly benches use (table in the
Tango section below): small, medium and large by default, --workload xlarge for a
~130k-target query, --synthetic name:packages:targets_per_package[:layers] for a custom size, and
--repo-url URL [--repo-from REV --repo-to REV] to add a real repository and commit pair.
--summary-out (default perf-proof-summary.md) is the markdown report: the headline verdict and
its reasons, both sides' commit, tree, --version and build, the environment, the correctness
table, and one table per workload with every stage and metric. --metrics-out (default
perf-proof-metrics.json) has the same plus every raw sample (user, sys, wall, peak RSS, sampled
RSS peak, Bazel CPU, exit codes) and the first differing keys of any mismatched output.
--keep-workdir keeps the scratch directory with the workspaces, both binaries and every stage's
log and output file.
bazel test //tools/perf:perf_proof_testThey cover the pure helpers: rusage normalisation, the ps and /proc parsers, the Mann-Whitney
test, the verdict rules, candidate-spec classification, hash-map diffing and the rendering, plus
measure_process on a real child process.
tango_compare.py benchmarks bazel-diff against
Uber's Tango (Target Analyzer in Go) on the same workspaces and
commit pairs, and cross-checks that both tools report the same impacted targets. The
perf-tango-compare workflow runs it nightly
and publishes the comparison as a step summary plus a 90-day metrics artifact.
Both tools compute impacted targets the same way: check out each revision, bazel query the whole
graph (deps(//...:all-targets), streamed proto), hash every target, diff the two hash maps. The
harness drives each tool through its own natural end-to-end flow on one workspace and one
base..head pair:
| bazel-diff | Tango | |
|---|---|---|
| Flow | git checkout base → generate-hashes → git checkout head → generate-hashes --depEdgesFile → get-impacted-targets (the README recipe) |
one get-changed-targets RPC to Tango's example server, which leases a worker clone, checks out and queries each revision, hashes, and compares |
| Timed as | wall time of the five stages (each also reported) | wall time seen by Tango's example client; the server's own total_duration is pulled from its log alongside |
| Includes | its two checkouts | its two checkouts |
Each flow's one-off setup (Tango cloning its origin and worker, both Bazel servers fetching
bazel_tools & co.) happens in an untimed warm-up. Then, per iteration:
- cold --
bazel shutdownfor both tools' servers, then run each. Fresh server start plus full graph load: what a CI job pays per PR today. - warm -- run each again with the servers alive (incremental re-analysis after the checkouts).
Tango runs with
-bypass-cacheso it recomputes rather than serving its cached result. - diff only -- no Bazel on either side: Tango with its result cache enabled (a treehash lookup)
next to bazel-diff's
get-impacted-targetsover the hash files already on disk. Informational.
Tool order alternates every iteration so neither tool consistently runs into a page cache the other
just warmed. Medians are reported; the ratio is Tango / bazel-diff, so above 1.00x means
bazel-diff was faster.
The impacted sets from the last iteration are compared label by label. The tools' semantics are
close enough that the synthetic workloads agree exactly; on real repositories differences (external
repository handling, generated files) are reported, not failed, unless --require-match is given.
Synthetic workspaces come from tools/firecracker/bench/gen_project.py:
layered genrule DAGs with real source files and no external toolchains, so query time is graph
load, not fetching. Presets (--workload):
| Preset | Packages | genrules / package | Rule targets |
|---|---|---|---|
tiny |
60 | 3 | 240 (smoke tests only) |
small |
400 | 4 | 2,000 |
medium |
1,500 | 4 | 7,500 |
large |
4,000 | 4 | 20,000 |
xlarge |
10,000 | 4 | 50,000 |
"Rule targets" counts genrules plus one filegroup per package; the query also sees
sources_per_package (3) source files and the genrule outputs per package, plus bazel_tools,
so xlarge is a ~130k-target bazel query. With no workload flags the harness runs the four
nightly presets.
Custom sizes: --synthetic name:packages:targets_per_package[:layers]. A real repository:
--repo-url URL --repo-from HEAD~1 --repo-to HEAD [--repo-clone-args --depth=50].
# Build bazel-diff, clone+build Tango at the pinned commit, run the four presets x 3 iterations.
python3 tools/perf/tango_compare.py --bazel ~/go/bin/bazelisk
# Smoke profile: tiny workload, one iteration, reusing an existing binary and Tango checkout.
python3 tools/perf/tango_compare.py --quick --skip-build --bazel-diff bazel-bin/src/bazel-diff \
--tango-dir ~/src/tango
# Keep everything on disk and write the report files the workflow publishes.
python3 tools/perf/tango_compare.py --workload medium --iterations 5 \
--workdir /tmp/tc --keep-workdir --metrics-out metrics.json --summary-out summary.mdRequirements: git, go 1.25+ (or any Go with GOTOOLCHAIN=auto, the default the harness sets,
so the right toolchain is fetched), a bazel/bazelisk binary, Python 3.9+. No third-party
Python. Tango's example server hard-codes 127.0.0.1:8081; the port must be free.
Tango is pinned to TANGO_PINNED_REF in the script so a Tango change never silently moves the
baseline. Compare against another Tango with --tango-ref <sha|branch|tag> (the workflow exposes
this as a dispatch input). --tango-pool-size 2 lets Tango analyse the two revisions in parallel on
two workers -- an architectural advantage it has over bazel-diff's sequential flow -- at the cost of
twice the Bazel servers; the default of 1 keeps the comparison sequential-vs-sequential.
--summary-out is GitHub-flavored markdown (the workflow appends it to $GITHUB_STEP_SUMMARY):
the per-workload timing table, bazel-diff's cold stage breakdown, the impacted-set agreement table,
and any failures. --metrics-out is JSON with the environment (versions, SHAs of both tools, CPU and
memory), per-phase medians/min/max, every raw sample (bazel-diff stages, Tango server-side
durations), and the full label diff when the tools disagree.
Exit status is non-zero when any run fails, and with --require-match also when the tools disagree.
bazel test //tools/perf:tango_compare_testThe harness is not a py_binary (it builds bazel-diff with bazel build, which would deadlock under
bazel run); the test covers the pure helpers between raw tool output and the summary.
cache_probe_bench.py is an experiment, not a feature. bazel-diff has
no cache-probe mode and the top-level README does not mention one. The
cache-probe-bench workflow runs this harness
nightly so the decision to add one (or not) rests on trend data rather than on a blog post. The
rule: the mode is not advertised until the cron shows it is sound (never misses a test that
ground truth ran) and a win on precision or wall time against the hash-based flow.
Aspect's aspect cache diff asks the
remote cache which actions it already holds instead of hashing targets. One bazel test //...
under --experimental_remote_require_cached executes nothing: every action is either a cache hit
or an EXECUTION_DENIED miss, and --remote_grpc_log records a GetActionResult per probed
action labelled with its target and mnemonic. A test is unaffected when its own TestRunner
action hits, because that action's key folds in the digests of its runfiles. Bazel enforces
require-cached only on the remote-execution path, so the probe points --remote_executor at
cache_probe/dummy_executor, a Go REAPI server that
advertises execution and never receives an Execute call (the harness counts them; any call
fails the run).
Two Bazel details the harness had to learn the hard way, both reproduced in its docstring:
- On a warm server Bazel memoizes action nodes and never re-queries the cache for them. The probe
therefore runs two passes: pass 1 flips
--remote_default_exec_properties, which changes the action-execution salt and drops every action node without re-analysis; pass 2 runs with the baseline flags plus--nouse_action_cacheso each action's lookup uses the baseline's key. - Seeding must start from
bazel clean: on a warm output basebazel testexecutes nothing and uploads nothing. The harness verifies every seed with a clean-tree probe that must report zero misses before it measures anything.
Per synthetic workload (the Tango presets plus two check_test targets per package, see
gen_project.py --tests-per-package) and per change scenario:
| Scenario | Edit | Why |
|---|---|---|
leaf_edit |
one source file ~75% deep in the graph | a PR-sized change |
identical_output |
an input whose genrule ignores its content | the action key moves, the output and everything downstream stay byte-identical: bazel-diff must flag the closure, the cache knows better |
wide_edit |
a layer-0 source with the most dependents | a shared-library change; stresses the miss frontier and rdeps attribution |
partial_leaf_edit, partial_identical_output |
the same two changes, selectors run against a cache seeded from only the lower half of the packages | what the probe sees when main's CI does not build everything: a miss then means "changed, or never run on main", and the probe cannot tell which |
Four selectors are scored against ground truth, the tests a real bazel test //... against
the fully seeded cache actually executes (what CI pays with no selector at all). The partial_*
scenarios keep that change-based truth, so recall still means "never misses a changed test" and
precision shows how much each selector overreports under a thinner cache; they also record how
many tests a full run against the partial cache executes (the change's tests plus everything main
never ran). They run one iteration of the warm selectors only, since their point is accuracy.
| Selector | Flow | Timed as |
|---|---|---|
| bazel-diff | checkout base, generate-hashes, checkout head, generate-hashes --depEdgesFile, get-impacted-targets, filtered to test targets |
the five stages, cold and warm |
| probe overreport | pass 1 + pass 2, decode the gRPC log, one tests(rdeps(//..., set(<frontier misses>))) query |
both passes, the decode and the query, cold and warm |
| probe precise | bazel build //... with upload (executes the missed non-test actions), then the probe; affected = tests whose own action missed |
the build plus the probe |
| probe hybrid | bazel-diff's impacted tests as candidates (recall), then bazel build of just those with upload and a probe scoped to just those (precision); affected = candidates whose own action missed |
bazel-diff warm plus the build plus the probe, what a serve-backed hybrid would pay |
Recall below 100% is a soundness failure (--require-sound makes it fail the run). Precision is
ground truth / flagged. The cache directory is snapshotted after the seed and restored before every
iteration so precise mode's uploads never leak into the next measurement. Medians are reported.
# Build the fixtures once (bazel-remote at the pinned version, the dummy executor) ...
python3 tools/perf/cache_probe_bench.py --install-fixtures-only --fixture-dir ~/cache-probe-bin
# ... then the smoke profile against an existing bazel-diff binary.
python3 tools/perf/cache_probe_bench.py --quick --skip-build --bazel-diff bazel-bin/src/bazel-diff \
--fixture-dir ~/cache-probe-bin --bazel ~/go/bin/bazelisk
# The nightly legs, keeping the scratch directory and writing the report files the workflow publishes.
python3 tools/perf/cache_probe_bench.py --workload small --workload medium --iterations 3 \
--fixture-dir ~/cache-probe-bin --workdir /tmp/cpb --keep-workdir \
--metrics-out metrics.json --summary-out summary.md --require-soundRequirements: git, go 1.25+, a bazel/bazelisk binary, Python 3.9+, stdlib only. All Bazel
commands run with --nohome_rc (bazel-diff included, through --bazelStartupOptions) so a
developer's own rc never changes action keys or streams to a BES. Unit tests for the pure helpers
(the proto-runtime-free gRPC log decoder, verdicts, result-line classification, accuracy math,
rendering):
bazel test //tools/perf:cache_probe_bench_test- gRPC caches only:
--remote_grpc_logis a gRPC client interceptor, so an HTTP remote cache or a disk cache yields no verdict at all. - A hit is sound; a miss is ambiguous (changed, never uploaded, or evicted). A sparse cache turns into overreporting, never into a missed test.
- Flag parity: the run that fills the cache and the probe must agree on every flag that enters an action key.
- Actions tagged
local,no-remoteorno-cachebypass the gate and execute during the probe. - The probe's analysis phase is paid in full every time (the salt flip throws away incremental
execution state); whether that beats two
generate-hashesruns is exactly what the cold/warm columns measure. - The probe answers "is this result cached", not "did this change touch it". With a fully seeded
cache the two coincide; the
partial_*scenarios measure how far they drift apart when they do not, and whether bounding the probe by bazel-diff's candidates (hybrid) keeps the drift in check.
partial_graph_bench.py is the nightly proof behind the opt-in
bazel-diff serve --partialGraph mode (see the top-level README, "Query Service"). The mode answers
a revision whose diff from the cached from entry only edits regular source content by
re-evaluating that entry's recorded hashing recipes against the new revision's git ls-tree -- no
checkout, no bazel query -- and falls back to a full generation for anything that can change the
graph. The partial-graph-bench workflow runs
this harness nightly; the mode stays opt-in until the trend shows it is exactly as accurate and
faster.
Three serve instances run one after another on the same workspace (so they share one Bazel
server and compare like for like):
| Instance | Flags | Role |
|---|---|---|
baseline |
--trackDeps |
ground truth and today's cost: a full generation of every to revision |
partial |
--partialGraph --trackDeps |
the derivation under test |
verify |
--partialGraph --trackDeps, fresh cache |
a full generation of every to revision under the mode, whose cache entry the partial server's must equal |
Per revision pair the harness asserts, and fails the run on (unless --no-require-match):
- accuracy --
/impacted_targetsand/impacted_targets_with_distancesagree label for label with the baseline, and the partial server's cache entry fortois byte-identical to the verify server's (hashes, dependency edges, module graph, recipes); - classifier correctness -- the scenarios that must derive report
generation.mode = derived, and the ones that must not reportfullwith apartialFallbackReason; - speed -- the
toretrieval and the whole request, derived versus the baseline's full generation, cold (Bazel server restarted before the query) and warm; the verify server's numbers show what recording recipes costs a full generation.
Synthetic workloads are the Tango-comparison presets from
gen_project.py, plus one tracked file no target reads
(docs/NOTES.md). Every scenario is committed on top of the base revision, once per warm iteration
and once more for the cold leg, with iteration-specific content so no two commits share a tree
(the serve cache is keyed by tree):
| Scenario | Edit | Expected |
|---|---|---|
leaf_edit |
one source file ~75% deep in the graph | derived |
wide_edit |
the layer-0 source with the most dependents | derived |
multi_edit |
ten sources spread across the packages | derived |
exec_bit |
flip a source's executable bit (and edit it) | derived |
unmatched_edit |
edit the tracked file no target reads | derived, empty impacted set |
chain |
a second leaf edit on top of the leaf_edit commit |
derived from a derived entry |
build_edit |
touch a BUILD.bazel (plus a leaf edit) |
full generation |
module_edit |
touch MODULE.bazel |
full generation |
add_file |
add an unreferenced file | full generation |
delete_file |
delete the unreferenced tracked file (plus a leaf edit) | full generation |
A real repository (--repo-url URL --repo-to REV --repo-commits N) is replayed instead along its
first-parent history, N consecutive pairs ending at REV. There is no expected mode for a real
commit, so the report shows how often real changes derive (the fallback rate the classifier's
conservatism costs) while every pair is still held to the accuracy checks.
# Build bazel-diff, then the two nightly presets (small, medium) x 2 warm iterations + 1 cold leg.
python3 tools/perf/partial_graph_bench.py --bazel ~/go/bin/bazelisk
# Smoke profile: tiny workload, one warm iteration, reusing an existing binary.
python3 tools/perf/partial_graph_bench.py --quick --skip-build --bazel-diff bazel-bin/src/bazel-diff
# Only some scenarios, keep the scratch directory, write the report files the workflow publishes.
python3 tools/perf/partial_graph_bench.py --workload medium --scenario leaf_edit --scenario build_edit \
--workdir /tmp/pgb --keep-workdir --metrics-out metrics.json --summary-out summary.md
# Replay ten commits of a real repository.
python3 tools/perf/partial_graph_bench.py --repo-url https://github.com/bazelbuild/bazel-skylib.git \
--repo-to HEAD --repo-commits 10 --workload skylib--serve-arg=<flag> adds a flag to every serve instance (a --bazelStartupOptions, a
--partialGraphRebuildPattern). Requirements: git, a bazel/bazelisk binary, Python 3.9+,
stdlib only.
--summary-out is GitHub-flavored markdown (the workflow appends it to $GITHUB_STEP_SUMMARY): per
workload the derived-pair count and a per-scenario table of expected and observed modes, baseline
cold and warm, the partial to retrieval and whole request, the verify full generation, the
speedup (baseline warm / partial to; the request column is warm legs only), and the two agreement columns; then every failure.
--metrics-out is JSON with the environment and, per pair, the three instances' timings and
profile fields (mode, partialFallbackReason, classifyMillis, deriveMillis,
changedSources, unmatchedPaths), the impacted-set and distance comparisons with the first
differing labels, and the entry comparison with the first differing hashes.
bazel test //tools/perf:partial_graph_bench_testThey cover the pure helpers: the scenario edit plans, reading the profile, set comparison, the per-pair checks, the medians and the rendering.