Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Consolidate benchmark recipes and cases (#3721)

Maximilian Roos970976bd32d1
diff --git a/.github/scripts/criterion-to-jsonl.py b/.github/scripts/criterion-to-jsonl.py
deleted file mode 100755
index 116ee7b99..000000000
--- a/.github/scripts/criterion-to-jsonl.py
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env python3
-"""Convert Criterion estimates into JSONL rows for time-series benchmark tracking.
-
-Walks `target/criterion/**/new/estimates.json` and prints one JSON line per
-benchmark group with timestamp, commit SHA, group name, and key statistics.
-"""
-
-import argparse
-import json
-from datetime import datetime, timezone
-from pathlib import Path
-
-
-def main() -> None:
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument("--sha", required=True, help="commit SHA to record")
- parser.add_argument(
- "--root",
- type=Path,
- default=Path("target/criterion"),
- help="Criterion output root (default: target/criterion)",
- )
- args = parser.parse_args()
-
- ts = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
- estimates = sorted(args.root.glob("**/new/estimates.json"))
- if not estimates:
- raise SystemExit(f"No criterion estimates found under {args.root}")
- for est in estimates:
- bench = est.relative_to(args.root).parent.parent.as_posix()
- data = json.loads(est.read_text())
- row = {
- "ts": ts,
- "sha": args.sha,
- "bench": bench,
- "mean_ns": data["mean"]["point_estimate"],
- "stddev_ns": data["std_dev"]["point_estimate"],
- }
- print(json.dumps(row))
-
-
-if __name__ == "__main__":
- main()
diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml
index c6cf6d667..5b1692add 100644
--- a/.github/workflows/benchmarks.yaml
+++ b/.github/workflows/benchmarks.yaml
@@ -48,22 +48,21 @@ jobs:
cache-bin: "false"
save-if: false
- - name: Install shells (zsh, fish)
- run: sudo apt-get update && sudo apt-get install -y zsh fish
+ - name: Install shells and jq
+ run: sudo apt-get update && sudo apt-get install -y zsh fish jq
- name: Install nushell
uses: hustcer/setup-nu@v3
with:
version: '0.114.1'
- - name: πŸ’° Rust repo cache
+ - name: πŸ’° Large-repository fixture cache
uses: actions/cache@v6
with:
- # wt-perf builds real-repo fixtures under target/wt-perf/bench-repos at
- # the workspace root. `cargo clean` would wipe them, so this cache
- # restores the ~15 GiB rust clone across runs.
+ # The fixture file pins the corpus revision. Including its hash keeps
+ # a prior corpus out of the cache after either constant changes.
path: target/wt-perf/bench-repos
- key: bench-repos-rust-${{ runner.os }}
+ key: bench-repos-large-repository-${{ runner.os }}-${{ hashFiles('benches/large-repository-fixture') }}
- name: πŸ“Š Run benchmarks
run: cargo bench
@@ -86,7 +85,23 @@ jobs:
GIST_ID: 19bb23cb9658722abfe69479d0a4f9bf
run: |
set -euo pipefail
- python3 .github/scripts/criterion-to-jsonl.py --sha "$GITHUB_SHA" > new-rows.jsonl
+ timestamp="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
+ find target/criterion -path '*/new/estimates.json' -print0 \
+ | sort -z \
+ | xargs -0 -r jq -c --arg ts "$timestamp" --arg sha "$GITHUB_SHA" '
+ {
+ ts: $ts,
+ sha: $sha,
+ bench: (
+ input_filename
+ | sub("^target/criterion/"; "")
+ | sub("/new/estimates\\.json$"; "")
+ ),
+ mean_ns: .mean.point_estimate,
+ stddev_ns: .std_dev.point_estimate
+ }
+ ' > new-rows.jsonl
+ test -s new-rows.jsonl
git clone "https://x-access-token:${GITHUB_TOKEN}@gist.github.com/${GIST_ID}.git" /tmp/gist
cat new-rows.jsonl >> /tmp/gist/results.jsonl
git -C /tmp/gist \
diff --git a/Cargo.lock b/Cargo.lock
index 8905464ca..33f5f2908 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4486,6 +4486,7 @@ dependencies = [
"clap",
"criterion",
"dunce",
+ "fs2",
"serde_json",
"tempfile",
"worktrunk",
diff --git a/Cargo.toml b/Cargo.toml
index 6be45e80e..a4ed23f73 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -99,12 +99,12 @@ syntax-highlighting = ["dep:tree-sitter-bash", "dep:tree-sitter-highlight"]
# Enable shell/PTY integration tests (requires bash, zsh, fish installed on system)
# Includes: shell wrapper tests, PTY-based approval prompts, TUI select, progressive rendering
shell-integration-tests = []
-# Enable benchmarks whose fixture is too large for hosted CI: the rust-scale
-# prune fixture (~15 GiB of rust-lang/rust worktrees, cached under
+# Enable benchmarks whose fixture is too large for hosted CI: the
+# large-repository prune fixture (~15 GiB of linked worktrees, cached under
# target/wt-perf/bench-repos). The daily benchmarks workflow runs plain `cargo bench`
# and must never build it; opt in locally with
-# `cargo bench --bench prune --features real-repo-benches`.
-real-repo-benches = []
+# `cargo bench --bench prune --features large-repository-benches`.
+large-repository-benches = []
# Install git-wt binary so `git wt` works as a git subcommand
git-wt = []
diff --git a/benches/CLAUDE.md b/benches/CLAUDE.md
index 5c5a20db1..9de3ae71d 100644
--- a/benches/CLAUDE.md
+++ b/benches/CLAUDE.md
@@ -13,8 +13,8 @@ cargo bench --bench list skeleton/warm
# Run specific group (all variants)
cargo bench --bench list full
-# GH #461 scenario (50 branches at varying history depths on rust-lang/rust)
-cargo bench --bench list real_repo_many_branches
+# GH #461 scenario (50 branches at varying depths in the large-repository corpus)
+cargo bench --bench list large_repository
# All list benchmarks (~1 hour)
cargo bench --bench list
@@ -25,7 +25,7 @@ cargo bench --bench time_to_first_output remove # just remove
# wt step prune (scan + removal on the squash-merged fixture)
cargo bench --bench prune # synthetic variants
-cargo bench --bench prune --features real-repo-benches prune_real_repo # rust scale (~15 GiB cached fixture)
+cargo bench --bench prune --features large-repository-benches prune_large_repository # large-repository scale (~15 GiB temporary fixture)
# Picker preview pre-compute (wt switch preview workload)
cargo bench --bench picker_preview # all variants
@@ -37,43 +37,52 @@ cargo bench --bench completion
## Fixtures and Benches
-**Bench groups are named for what they measure; fixtures for the repo shape they
-build.** The two never match by convention because the relationship is
-many-to-one β€” one fixture feeds several bench groups that measure different
-things (`RepoConfig::typical` alone backs five). Don't read a bench group and its
-fixture as duplicates of each other: `full` is a benchmark, `mixed` is the repo
-it runs on.
-
-| Fixture (generator) | `wt-perf setup` handle | Bench group(s) |
+Bench groups name measurements; fixture recipes are implementation details
+that construct repository states. Preserve the state dimensions needed for
+coverage and fidelity, not historical recipes or the ability to recreate an
+old setup. Consolidate or rename recipes whenever the resulting benchmarks
+still test the same performance claims. Prefer a few heterogeneous canonical
+states: a property does not need its own recipe merely because one benchmark
+studies it. Split a fixture only when a controlled contrast, destructive
+precondition, or disproportionate setup cost requires a different state. One
+recipe can feed several groups (`FixtureRecipe::Typical` backs five); for
+example, `full` is a benchmark and `Mixed` is its repository state.
+
+| Fixture recipe | `wt-perf setup` | Bench group(s) |
|---|---|---|
-| `RepoConfig::typical(N)` | `typical-N` | `skeleton`, `worktree_scaling` (list.rs); `first_output` (time_to_first_output.rs); `picker_preview`; `remove_e2e` |
-| `RepoConfig::branches(N, M)` | `branches-N[-M]` | β€” (branch-scaling investigation only) |
-| `RepoConfig::many_divergent_branches()` | `divergent` | `divergent_branches` (list.rs) |
-| `create_mixed_repo(W, B, R)` | `mixed-W-B[-R]` | `full` (list.rs); `completion_switch` (completion.rs) |
-| `create_prune_repo(M, U)` | `prune-M-U` | `prune_e2e` (prune.rs) |
-| `ensure_prune_real_repo(M, U)` | `prune-real[-M-U]` | `prune_real_repo` (prune.rs) |
-| rust-lang/rust clone (`clone_rust_repo`) | β€” | `real_repo`, `real_repo_many_branches` (list.rs) |
-| `lean_worktrees` (local to alias.rs) | β€” | `dispatch` (alias.rs) |
-| `RepoConfig::picker_test()` | `picker-test` | β€” (interactive picker debugging only) |
-
-Renaming a bench group is not free: `.github/scripts/criterion-to-jsonl.py`
-keys each time-series row by the criterion output path (`<group>/<id>`), and the
-daily `benchmarks` workflow appends those to a gist. A rename orphans that
-series.
-
-Every ephemeral generator returns `FixtureRepo`, the owner of the temporary
-root plus the canonical primary/linked-worktree paths. Repo-bound benchmark
+| `Typical { total_worktrees: N }` | `setup typical N --path <path>` | `skeleton`, `worktree_scaling` (list.rs); `first_output` (time_to_first_output.rs); `picker_preview`; `remove_e2e` |
+| `Minimal { branchless_branches: B, linked_worktrees: W }` | `setup minimal B W --path <path>` | `dispatch` (alias.rs) |
+| `SyntheticDivergence` | `setup synthetic-divergence --path <path>` | `divergent_branches` (list.rs) |
+| `LargeRepository` | `setup large-repository --path <path>` | `large_repository` (list.rs) |
+| `Mixed { linked_worktrees: W, branchless_branches: B, remote_tracking_refs: R }` | `setup mixed W B R --path <path>` | `full` (list.rs); `completion_switch` (completion.rs) |
+| `Prune { candidate_pairs: M, backdrop_pairs: U }` | `setup prune M U --path <path>` | `prune_e2e` (prune.rs) |
+| `LargeRepositoryPrune { candidate_pairs: M, backdrop_pairs: U }` | `setup large-repository-prune M U --path <path>` | `prune_large_repository` (prune.rs) |
+
+`total_worktrees` includes the primary worktree. `linked_worktrees` excludes it.
+`branchless_branches` have no linked worktree. `remote_tracking_refs` excludes
+the `origin/main` and `origin/HEAD` pair every synthetic fixture has. Each prune
+count is a pair: one linked worktree and one branchless branch.
+The canonical large-repository fixture has eight worktrees and fifty branches
+spread across its most recent 5,000 commits.
+
+Every benchmark recipe returns `FixtureRepo`, the owner of the temporary root
+plus the canonical primary/linked-worktree paths. Repo-bound benchmark
subprocesses start through `wt_command`, and warm/cold matrices use
`CacheState::WARM_AND_COLD`; keep lifecycle, environment isolation, and cache
-labels in those shared APIs rather than re-deriving them in a bench target.
+labels in those shared APIs.
-## Rust Repo Caching
+## Large-repository corpus
-Real repo benchmarks clone rust-lang/rust on first run (~2-5 minutes). The clone is cached in `target/wt-perf/bench-repos/` and reused. Corrupted caches are auto-recovered.
+`benches/large-repository-fixture` pins the corpus and commit.
+The first matching acquisition clones that revision; later runs reuse the
+revision-keyed source under `target/wt-perf/bench-repos/large-repository/`.
+Source construction is locked across processes, built in a temporary sibling,
+validated, then atomically renamed into place. Mutable benchmark fixtures are
+always fresh and have no shared lock or repair state.
## Faster Iteration
-Criterion has no exclusion flag β€” narrow the run by picking a substring that matches only the variants you want. Benchmark IDs look like `<group>/<label>/<param>`, e.g. `skeleton/cold/4`, `worktree_scaling/warm/8`, `full/cold`, `real_repo_many_branches/warm`.
+Criterion has no exclusion flag β€” narrow the run by picking a substring that matches only the variants you want. Benchmark IDs look like `<group>/<label>/<param>`, e.g. `skeleton/cold/4`, `worktree_scaling/warm/8`, `full/cold`, `large_repository/branches/warm`.
**Pattern matching (positional `FILTER`):**
```bash
@@ -84,7 +93,7 @@ cargo bench --bench list full # Both cache states of the combined
cargo bench --bench list -- --exact full/cold # One exact ID
```
-To skip the slow real-repo and divergent groups, target the synthetic groups directly: `cargo bench --bench list skeleton`, `cargo bench --bench list worktree_scaling`, or `cargo bench --bench list full`. Run them sequentially if you want more than one.
+To skip the slow large-repository and divergent groups, target the synthetic groups directly: `cargo bench --bench list skeleton`, `cargo bench --bench list worktree_scaling`, or `cargo bench --bench list full`. Run them sequentially if you want more than one.
The `full` group is the place to start when `wt list` regresses on a real mix of worktrees and branches: the cold/warm split says whether the cost is the persistent-cache fill (cold) or the per-process re-fork (warm). A `full` wall time can't be split by side (the git subprocesses overlap on the rayon pool), so to localize a regression, trace one invocation and read the profile's BY CONTEXT table ("Analyzing a trace" below); `worktree_scaling` and `divergent_branches` track the worktree side and branch side respectively at criterion cadence.
@@ -122,27 +131,23 @@ Worktrunk maintains a persistent SHA-keyed cache at `.git/wt/cache/` plus a git-
cache of the default branch at `worktrunk.default-branch`. Both survive process exits,
so bench iterations read from prior iterations unless invalidated.
-**Rule:** if a benchmark runs a `wt` subcommand that populates these caches, every
-iteration must start cold β€” otherwise iter 1 measures the real cost and iter 2+ measure
-a cache hit. Run the iteration through `wt_perf::bench_wt`, the one home of the
-warm/cold strategy (plain `iter` warm; invalidate-per-iteration full- or
-probe-cold, picked by `CacheState` β€” its doc comment carries the
-`BatchSize::PerIteration` rationale). A benchmark whose setup is not plain
-invalidation (e.g. `remove_e2e` recreating the removed worktree, prune's
-`live` re-creating its candidates) uses `iter_batched` with
-`BatchSize::PerIteration` directly. Timed iterations assert only the child's
-exit status; anything stronger (candidate counts, fixture shape) runs once
-outside the timed loop (see `verify_candidates` in `benches/prune.rs`).
+**Rule:** explicitly choose cache state for every benchmark that runs a `wt`
+subcommand which populates these caches. Run ordinary warm/cold variants through
+`wt_perf::bench_wt`, the one home of the shared strategy. Destructive variants
+use `iter_custom`: each iteration builds a fresh fixture before starting the
+timer, measures only the command, and checks the postcondition before returning
+the accumulated duration. `remove_e2e` prewarms its fresh fixture through the
+same integration probes to preserve its historical cache-warm scenario;
+`prune_e2e/live` clears probe caches to preserve its probe-cold scenario.
`invalidate_caches_auto` clears:
-- `.git/index` (main and linked worktrees)
- `.git/objects/info/commit-graph*`
- `.git/wt/cache/` (all sha_cache kinds + ci-status + summaries)
- `worktrunk.default-branch` (git config)
-`.git/packed-refs` is deliberately preserved: `create_repo_at` runs `git gc`
-at the end of fixture setup, which packs every loose ref into `packed-refs`
+`.git/packed-refs` is deliberately preserved: flat fixture setup runs `git gc`
+at the end, which packs every loose ref into `packed-refs`
and prunes the loose copies. Deleting that file post-gc leaves the repo with
no resolvable refs, so any bench that resolves a branch (e.g. the `with_vars`
alias's `{{ commit }}` template var) blows up partway through warm-up.
@@ -152,22 +157,11 @@ User state β€” `worktrunk.history`, `worktrunk.hints.*`, `worktrunk.state.<branc
read-path performance and benches may depend on it (e.g., branch markers set during
setup).
-**Deleting a worktree's index isn't a cold cache.** Git treats a missing index
-as empty, so `git status` reports every tracked file as a staged deletion β€” a
-*different repo state*, which flips any clean-worktree gate a benchmarked
-command exercises (e.g. `wt step prune`'s removability check would silently
-drop every worktree candidate). A benchmark exercising such a gate must
-invalidate with `wt_perf::invalidate_probe_caches` instead, which clears only
-`.git/wt/cache/`: the integration probes re-run while git's own state stays
-warm β€” indexes with stat data, commit graph, `worktrunk.default-branch` β€”
-exactly the state a real repo is in right after a fetch. The prune benches use
-it (via `bench_wt`'s `ProbeCold` state) for their `dry_run_probe_cold`
-variants; a one-time post-setup dry-run (`verify_candidates`) pins the
-candidate count, so a gate-flipping invalidation can't silently shrink the
-scanned workload. (`ensure_prune_real_repo` heals a
-fixture whose indexes were deleted by a stray `wt-perf invalidate` /
-`timeline --cold`, rebuilding them via `git reset -q` β€” safe there because the
-fixture's only dirt is untracked files.)
+Worktree indexes survive every cache state. Git treats a missing index as every
+tracked file being staged for deletion, which changes the repository rather
+than cooling it. `invalidate_probe_caches` clears only `.git/wt/cache/`; the
+prune benches use it for the first-scan-after-fetch shape while git metadata
+stays warm.
**Which commands populate `.git/wt/cache/`:**
@@ -201,7 +195,7 @@ worth measuring at CI cadence.
- Cold cache penalty: ~5-16% slower
- Scaling: Linear with worktree count
-**Large repos** (rust-lang/rust):
+**Large repositories** (current corpus: rust-lang/rust):
- Cold cache penalty: ~4x slower for single worktree
- Scaling: Warm cache shows superlinear degradation, cold cache scales better
@@ -212,14 +206,14 @@ detached background processes; a single e2e number hides which phase moved.
Record them in two layers:
**Criterion cadence** β€” `benches/remove.rs` and `benches/prune.rs`. Expected
-numbers on an M-series Mac (`prune-4-8` fixture: 4 squash-merged worktrees +
-4 squash-merged branches as candidates, 8 two-sided-diverged worktrees + 8
-diverged branches as backdrop, 200 commits, 100 files; `prune_real_repo` runs
-warm and probe-cold dry-runs on the `prune-real` fixture β€” a rust-lang/rust clone with 12
-squash-merged candidate pairs + 24 diverged worktrees and 24 diverged
-branches, i.e. 36 linked worktrees, cached and self-repairing in
-`target/wt-perf/bench-repos/rust-prune-12-24/`. That group is opt-in β€”
-`cargo bench --bench prune --features real-repo-benches prune_real_repo` β€”
+numbers on an M-series Mac (`Prune { candidate_pairs: 4, backdrop_pairs: 8 }`:
+4 squash-merged worktrees and 4 squash-merged branches as candidates, plus 8
+two-sided-diverged worktrees and 8 branches as backdrop, over 200 commits and
+100 files; `prune_large_repository` uses the pinned large-repository corpus
+with 12 candidate pairs and 24 backdrop pairs, i.e. 36 linked worktrees.
+The source clone is cached, but the mutable ~15 GiB fixture is built fresh for
+the benchmark process and removed when it exits. That group is opt-in β€”
+`cargo bench --bench prune --features large-repository-benches prune_large_repository` β€”
because its ~15 GiB fixture must never build on a hosted CI runner):
| Variant | Expected | What it measures |
@@ -227,21 +221,14 @@ because its ~15 GiB fixture must never build on a hosted CI runner):
| `prune_e2e/dry_run_probe_cold` | ~150 ms | full parallel scan, probes re-run (`.git/wt/cache/` cleared; git's own caches stay warm β€” the "first prune after fetching main" shape) |
| `prune_e2e/dry_run_warm` | ~60 ms | steady-state re-scan, probes hit sha_cache |
| `prune_e2e/live` | ~400 ms | probe-cold scan + parallel removal of the 8 candidates (worktree candidates ~145 ms each β€” mostly the fsmonitor-daemon stop β€” branch-only ~50 ms, concurrent on the removal worker pool under the scan lock's read side, reusing scan-time plans) |
-| `prune_real_repo/dry_run_warm` | ~0.25–0.8 s | steady-state scan of 72 items (36 worktrees + 36 branches) at 331k-commit scale |
-| `prune_real_repo/dry_run_probe_cold` | ~0.6–1 s | the same 72-item scan with probes re-running at real cost (statuses stay stat-warm) |
+| `prune_large_repository/dry_run_warm` | ~0.25–0.8 s | steady-state scan of 72 items (36 worktrees + 36 branches) at 331k-commit scale |
+| `prune_large_repository/dry_run_probe_cold` | ~0.6–1 s | the same 72-item scan with probes re-running at real cost (statuses stay stat-warm) |
| `first_output/remove` | ~86 ms | single-target validation up to first output (`benches/time_to_first_output.rs`) |
-Full-cold and live at rust scale are **one-shot timelines, not criterion
-groups** (a full-cold criterion iteration costs ~1 min in re-hashing statuses
-alone; a live one consumes the candidates). Expected one-shots on the
-`prune-real` fixture:
-
-- **full-cold dry-run ~5.5–7 s wall** (46–92 s CPU over ~480 subprocesses
- absorbed by the rayon pool) β€” the fresh-fixture shape, dominated by
- stat-cold `git status` at ~4.5–6.5 s per fresh worktree; the probes are
- `merge-base --is-ancestor` ~40 ms and `merge-tree --write-tree` ~130 ms (vs
- 4–25 ms synthetic, where shallow history walks bottom out at
- subprocess-spawn cost)
+Full-cold and live at large-repository scale are **one-shot timelines, not
+criterion groups**. Full-cold adds commit-graph rebuilding; live consumes the
+candidates. The live one-shot on the large-repository fixture is:
+
- **live ~0.6 s wall** β€” all 24 removals run concurrently on the removal
worker pool inside the `prune-scan` window (read side of the scan lock):
the 12 worktree candidates ~240–290 ms each, branch-only ~100–135 ms.
@@ -252,24 +239,21 @@ alone; a live one consumes the candidates). Expected one-shots on the
When candidate branches are packed (post-`gc`), the CAS deletes serialize
on `packed-refs.lock`, putting a floor under the branch-deletion tail
-This is the "prune takes many seconds" experience users report: worktree
-count Γ— stat-cold statuses bounds the scan, and the removal tail extends it
-by roughly one candidate's chain.
+An actual first checkout can be slower because every worktree status is
+stat-cold. The cache helpers preserve indexes because removing one changes
+staged state; use a fresh fixture when investigating checkout-cold status.
The synthetic fixture can't show it β€” its statuses are milliseconds β€” so
-scale-sensitive changes need a one-shot on `prune-real` (or
-`wt-perf timeline -- -C <repo> step prune --dry-run` on a real repo) alongside
-the criterion cadence. All rust-scale numbers are I/O-bound and move with
-ambient machine load (sibling builds, Spotlight): treat them as shape, not
-thresholds, and read criterion "regressed" verdicts on this bench against
-`uptime` before believing them.
+scale-sensitive changes need a one-shot on a fresh large-repository
+fixture (or `wt-perf timeline -- -C <repo> step prune --dry-run` on a real
+repository) alongside the criterion cadence. All large-repository numbers are
+I/O-bound and move with ambient machine load (sibling builds, Spotlight):
+treat them as shape, not thresholds, and compare Criterion verdicts with
+`uptime`.
The probe-cold prune benches run through `bench_wt` with
-`CacheState::ProbeCold`, never full invalidation (see "Deleting a worktree's
-index isn't a cold cache" under Cache Handling). Fixture correctness is
-checked once, outside the timed loops: a post-setup dry-run must list the
-expected candidate count, and a live run that removed nothing trips the next
-iteration's candidate re-creation (branch-name collision) instead of being
-silently timed.
+`CacheState::ProbeCold`. Fixture correctness is checked outside the timed
+loops: a post-setup dry-run pins the candidate count, and every live sample
+must consume its fresh fixture's candidate refs while retaining the backdrop.
**Phase attribution** β€” `wt-perf timeline` plus the removal spans. Prune emits
`prune-gather` (worktree+branch enumeration), `prune-scan` (the whole parallel
@@ -284,30 +268,23 @@ metadata-pruning β€” `removal_needs_write` in `src/commands/step/prune.rs`) also
wait for every in-flight check and removal to drain first.
```bash
-cargo run -p wt-perf -- setup prune-4-8 --path /tmp/prune-repo
-# A freshly built fixture is already probe-cold (empty sha_cache); don't use
-# `timeline --cold` here β€” it deletes worktree indexes, which flips prune's
-# clean-worktree gate and drops the worktree candidates from the run.
+cargo run -p wt-perf -- setup prune 4 8 --path /tmp/prune-repo
+# A freshly built fixture is already probe-cold (empty sha_cache).
cargo run -p wt-perf -- timeline -- -C /tmp/prune-repo step prune --dry-run --min-age 0s
cargo run -p wt-perf -- timeline -- -C /tmp/prune-repo step prune --min-age 0s
```
-**Live prune at real scale is a one-shot timeline, not a criterion group** β€”
-each live run consumes the candidates, and re-creating them on rust costs
-minutes per iteration. The `prune-real[-M-U]` fixture is built for this
-workflow: it lives in `target/wt-perf/bench-repos/` (no `--path`), and after a live
-prune the next `wt-perf setup prune-real` or `prune_real_repo` bench run
-detects the consumed candidates and re-creates just them (~1 min) instead of
-rebuilding the ~15 GiB fixture. Don't run two builders concurrently (a bench
-and a setup racing can wipe each other's half-built tree), and don't
-`wt-perf invalidate` it β€” deleting worktree indexes flips prune's
-clean-worktree gate; the next setup/bench call heals that, but the run you
-invalidated for measures a degraded scan:
+**Live prune at large-repository scale is a one-shot timeline, not a criterion group** β€”
+each live run consumes the candidates, and constructing the ~15 GiB fixture
+costs minutes. Give setup a new explicit path; it refuses to overwrite an
+existing destination. The pinned source clone is reused, while the mutable
+fixture has no cache state to validate or repair. The probe-cold timeline keeps
+git metadata warm:
```bash
-cargo run -p wt-perf -- setup prune-real # build or validate/repair the cache
-cargo run -p wt-perf -- timeline -- -C target/wt-perf/bench-repos/rust-prune-12-24/repo step prune --min-age 0s
-cargo run -p wt-perf -- setup prune-real # repair the consumed candidates
+cargo run -p wt-perf -- setup large-repository-prune 12 24 --path /tmp/prune-rust
+cargo run -p wt-perf -- timeline -- -C /tmp/prune-rust step prune --min-age 0s
+# For another run, remove /tmp/prune-rust explicitly or choose a new path.
```
**The `wt remove` exit-delay is machine-dependent and invisible to benches.**
@@ -325,16 +302,15 @@ count.
## Output Locations
-Fixture repos live under `target/wt-perf/` at the workspace root. That is
-per-worktree (git worktrees don't share `target/`) and reaped by `cargo clean`,
-so an expensive fixture β€” the ~15 GiB rust clone under `bench-repos/` β€” is
-rebuilt per worktree and after every `cargo clean`. `wt-perf setup` prints the
-exact path.
+Ephemeral synthetic fixtures use the system temporary directory. Manual
+`wt-perf setup` fixtures live at the explicit `--path` and are never
+overwritten. The revision-keyed large-repository source and temporary
+large-prune runs live under `target/wt-perf/bench-repos/`; that directory is
+per-worktree and reaped by `cargo clean`.
- Results: `target/criterion/`
-- Cached rust repo: `target/wt-perf/bench-repos/rust/`
-- Cached rust prune fixture: `target/wt-perf/bench-repos/rust-prune-<M>-<U>/` (repo +
- sibling worktrees + `round` counter for candidate re-creation)
+- Cached corpus source: `target/wt-perf/bench-repos/large-repository/source-<revision>/`
+- Temporary large-prune runs: `target/wt-perf/bench-repos/large-repository/runs/`
- HTML reports: `target/criterion/*/report/index.html`
## Performance Investigation with wt-perf
@@ -344,28 +320,15 @@ Use `wt-perf` to set up benchmark repos and generate Chrome Trace Format for vis
### Setting up benchmark repos
```bash
-# Set up a repo with 8 worktrees (persists at target/wt-perf/typical-8; the
-# next `setup typical-8` run wipes and rebuilds it)
-cargo run -p wt-perf -- setup typical-8
-
-# Available configs:
-# typical-N - 500 commits, 100 files, N worktrees
-# branches-N - N branches, 1 commit each
-# branches-N-M - N branches, M commits each
-# divergent - 200 branches Γ— 20 commits (GH #461 scenario)
-# mixed-W-B[-R] - W worktrees + B branches in varied states, plus R
-# remote-tracking refs (the `full` and completion fixture)
-# prune-M-U - M squash-merged candidates + U two-sided-diverged
-# worktrees/branches (the `wt step prune` workload; see
-# benches/prune.rs)
-# prune-real[-M-U] - rust-lang/rust clone + M squash-merged candidate pairs
-# + U diverged worktrees/branches (default 12-24), cached
-# and self-repairing in target/wt-perf/bench-repos/ (no --path);
-# first run clones from the network
-# picker-test - Config for wt switch interactive picker testing
-
-# Invalidate caches for cold run
-cargo run -p wt-perf -- invalidate target/wt-perf/typical-8
+# Set up a repo with 8 worktrees. The destination must not exist.
+cargo run -p wt-perf -- setup typical 8 --path /tmp/wt-typical-8
+
+# `wt-perf setup --help` lists every recipe and its semantic count names.
+# Reproduce the completion fixture, including its remote-tracking-ref population:
+cargo run -p wt-perf -- setup mixed 80 80 1400 --path /tmp/wt-mixed
+
+# Build a fresh large-repository prune fixture from the cached pinned source:
+cargo run -p wt-perf -- setup large-repository-prune 12 24 --path /tmp/prune-rust
```
### Generating traces
@@ -463,9 +426,10 @@ Three questions drive `wt list` performance work:
### Generating traces from benchmark repos
```bash
-# Trace on rust-lang/rust (must run benchmark first to clone)
-cargo run --release -q -- -vv -C target/wt-perf/bench-repos/rust list --progressive --branches
-cargo run -p wt-perf -- trace target/wt-perf/bench-repos/rust/.git/wt/logs/trace.jsonl > rust-trace.json
+# Trace the canonical large-repository fixture
+cargo run -p wt-perf -- setup large-repository --path /tmp/wt-history-spread
+cargo run --release -q -- -vv -C /tmp/wt-history-spread list --progressive --branches
+cargo run -p wt-perf -- trace /tmp/wt-history-spread/.git/wt/logs/trace.jsonl > large-repository-trace.json
```
## Key Performance Insights
@@ -474,12 +438,12 @@ cargo run -p wt-perf -- trace target/wt-perf/bench-repos/rust/.git/wt/logs/trace
This command walks the commit graph to compute divergence. On rust-lang/rust:
- Takes ~2s regardless of how many refs are queried
-- Only way to avoid it is to not enumerate branches at all
+- Its cost is driven primarily by history depth, not the number of rendered rows
-**Branch enumeration costs** (rust-lang/rust with 50 branches):
+**Branch-row costs** (rust-lang/rust with 50 branch-only rows):
- First run (cold persistent cache): ~15-18s (expensive merge-base/merge-tree per branch)
- Subsequent runs (warm persistent cache): ~2-3s (cache hits on merge-tree / integration probes / diff stats / ancestry)
-- Worktrees only: ~600ms (no branch enumeration)
+- Default rows only: ~600ms (the same ref capture, without branch-only integration and rendering tasks)
The persistent SHA-keyed cache (`.git/wt/cache/`) amortizes the first-run cost across
subsequent invocations. Cache entries are eternally valid since they're keyed on commit
diff --git a/benches/alias.rs b/benches/alias.rs
index 02c753002..43410f7ea 100644
--- a/benches/alias.rs
+++ b/benches/alias.rs
@@ -33,11 +33,13 @@ use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use std::path::Path;
use std::process::Command;
use worktrunk::testing::isolate_subprocess_env;
-use wt_perf::{CacheState, RepoConfig, bench_wt, create_repo, run_and_check, wt_command};
+use wt_perf::{
+ CacheState, FixtureRecipe, bench_wt, run_and_check, standard_benchmark_profile, wt_command,
+};
/// Alias body is a shell builtin so the wall-clock is dominated by the
/// parent's dispatch β€” not by running a real subcommand.
-const STUB_CONFIG: &str = "[aliases]\nstub = \"echo hello\"\n";
+const STUB_CONFIG: &str = "[aliases]\nstub = \": fixed fixed fixed fixed fixed fixed\"\n";
/// Alias body references vars that drive the expensive paths in
/// `build_hook_context`: `commit` / `short_commit` (`rev-parse <branch>`
@@ -45,21 +47,12 @@ const STUB_CONFIG: &str = "[aliases]\nstub = \"echo hello\"\n";
/// (lookup). `branch` and `worktree_path` are nearly free but kept so a
/// future filter sees them as "referenced". `upstream` is omitted because
/// fixture branches have no configured upstream β€” adding one would change
-/// what the stub variant measures and break label continuity.
+/// what the stub variant measures and break label continuity. Both aliases
+/// use the same no-output builtin and argument count.
const WITH_VARS_CONFIG: &str = r#"[aliases]
-with_vars = "echo {{ branch }} {{ default_branch }} {{ commit }} {{ short_commit }} {{ primary_worktree_path }} {{ worktree_path }}"
+with_vars = ": {{ branch }} {{ default_branch }} {{ commit }} {{ short_commit }} {{ primary_worktree_path }} {{ worktree_path }}"
"#;
-/// Lean repo config for the scaling rows β€” alias dispatch doesn't care
-/// about commit history depth, so minimal everything keeps setup under
-/// 10s at 100 worktrees (vs. ~60s for `RepoConfig::typical(100)`).
-const fn lean_worktrees(worktrees: usize) -> RepoConfig {
- RepoConfig {
- worktrees,
- ..RepoConfig::branches(0, 0)
- }
-}
-
/// Build an isolated `wt` invocation pointed at a fixture user config.
fn wt_cmd(binary: &Path, repo: &Path, user_config: &Path, args: &[&str]) -> Command {
let mut cmd = wt_command(binary, repo, Some(user_config));
@@ -83,8 +76,12 @@ fn bench_dispatch(c: &mut Criterion) {
});
});
- for worktrees in [1usize, 100] {
- let fixture = create_repo(&lean_worktrees(worktrees));
+ for total_worktrees in [1usize, 100] {
+ let fixture = FixtureRecipe::Minimal {
+ branchless_branches: 0,
+ linked_worktrees: total_worktrees - 1,
+ }
+ .create();
let stub_config = fixture.root().join("stub-config.toml");
let vars_config = fixture.root().join("with-vars-config.toml");
std::fs::write(&stub_config, STUB_CONFIG).unwrap();
@@ -104,14 +101,18 @@ fn bench_dispatch(c: &mut Criterion) {
None => cache_label.to_string(),
};
- group.bench_with_input(BenchmarkId::new(id, worktrees), &worktrees, |b, _| {
- // Cold matters here: `build_hook_context` resolves the
- // default branch, which writes `worktrunk.default-branch`
- // and would otherwise be a cache hit on iters 2-N.
- bench_wt(b, fixture.path(), cache, || {
- wt_cmd(binary, fixture.path(), user_config, &[alias_name])
- });
- });
+ group.bench_with_input(
+ BenchmarkId::new(id, total_worktrees),
+ &total_worktrees,
+ |b, _| {
+ // Cold matters here: `build_hook_context` resolves the
+ // default branch, which writes `worktrunk.default-branch`
+ // and would otherwise be a cache hit on iters 2-N.
+ bench_wt(b, fixture.path(), cache, || {
+ wt_cmd(binary, fixture.path(), user_config, &[alias_name])
+ });
+ },
+ );
}
}
}
@@ -121,10 +122,7 @@ fn bench_dispatch(c: &mut Criterion) {
criterion_group! {
name = benches;
- config = Criterion::default()
- .sample_size(30)
- .measurement_time(std::time::Duration::from_secs(15))
- .warm_up_time(std::time::Duration::from_secs(3));
+ config = standard_benchmark_profile();
targets = bench_dispatch
}
criterion_main!(benches);
diff --git a/benches/completion.rs b/benches/completion.rs
index 113fea4b9..4572c4159 100644
--- a/benches/completion.rs
+++ b/benches/completion.rs
@@ -29,14 +29,16 @@
//!
//! ```bash
//! cargo bench --bench completion
-//! cargo run -p wt-perf -- setup mixed-80-80-1400 --path /tmp/clone # same repo, by hand
+//! cargo run -p wt-perf -- setup mixed 80 80 1400 --path /tmp/clone
//! ```
use criterion::{Criterion, criterion_group, criterion_main};
+use std::collections::BTreeSet;
use std::path::Path;
-use wt_perf::{create_mixed_repo, run_and_check, wt_command};
+use std::process::Output;
+use wt_perf::{FixtureRecipe, run_and_check, wt_command};
-fn run_completion(binary: &Path, repo_path: &Path, words: &[&str]) {
+fn run_completion(binary: &Path, repo_path: &Path, words: &[&str]) -> Output {
let index = words.len().saturating_sub(1);
let mut cmd = wt_command(binary, repo_path, None);
cmd.arg("--").args(words);
@@ -45,7 +47,28 @@ fn run_completion(binary: &Path, repo_path: &Path, words: &[&str]) {
.env("_CLAP_COMPLETE_COMP_TYPE", "9")
.env("_CLAP_COMPLETE_SPACE", "true")
.env("_CLAP_IFS", "\n");
- run_and_check(&mut cmd);
+ run_and_check(&mut cmd)
+}
+
+fn expected_branches(branchless_branches: usize, linked_worktrees: usize) -> BTreeSet<String> {
+ std::iter::once("main".to_string())
+ .chain((0..branchless_branches).map(|i| format!("br-{i:04}")))
+ .chain((0..linked_worktrees).map(|i| format!("wt-{i:04}")))
+ .collect()
+}
+
+fn assert_completion_candidates(binary: &Path, repo_path: &Path, expected: &BTreeSet<String>) {
+ let output = run_completion(binary, repo_path, &["wt", "switch", ""]);
+ let stdout = String::from_utf8(output.stdout).unwrap();
+ let candidates: Vec<String> = stdout.lines().map(str::to_string).collect();
+ let actual: BTreeSet<String> = candidates.iter().cloned().collect();
+
+ assert_eq!(
+ actual.len(),
+ candidates.len(),
+ "completion returned duplicate candidates: {candidates:?}"
+ );
+ assert_eq!(&actual, expected, "unexpected completion candidates");
}
fn bench_completion_switch(c: &mut Criterion) {
@@ -53,7 +76,13 @@ fn bench_completion_switch(c: &mut Criterion) {
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
group.bench_function("mixed", |b| {
- let fixture = create_mixed_repo(80, 80, 1400);
+ let fixture = FixtureRecipe::Mixed {
+ linked_worktrees: 80,
+ branchless_branches: 80,
+ remote_tracking_refs: 1400,
+ }
+ .create();
+ assert_completion_candidates(binary, fixture.path(), &expected_branches(80, 80));
b.iter(|| run_completion(binary, fixture.path(), &["wt", "switch", ""]));
});
diff --git a/benches/large-repository-fixture b/benches/large-repository-fixture
new file mode 100644
index 000000000..53af6bc0b
--- /dev/null
+++ b/benches/large-repository-fixture
@@ -0,0 +1,2 @@
+pub const CORPUS: &str = "rust-lang/rust";
+pub const REVISION: &str = "be3d26db984c6f96335faca1f254dc04873cb1c1";
diff --git a/benches/list.rs b/benches/list.rs
index ee3c790cc..870c01edb 100644
--- a/benches/list.rs
+++ b/benches/list.rs
@@ -7,10 +7,8 @@
// in varied states, with branch divergence spread across history depth.
// The realistic "everything at once" workload (warm + cold).
// - divergent_branches: 200 branches Γ— 20 commits / GH #461 deep-divergence stress (warm + cold)
-// - real_repo: rust-lang/rust clone (8 worktrees; warm + cold)
-// - real_repo_many_branches: 50 branches at different history depths / GH #461
-// - warm: all branches (first run expensive; subsequent runs hit persistent cache)
-// - warm_worktrees_only: no branch enumeration (~600ms)
+// - large_repository: one pinned large corpus with 8 worktrees and 50 branches
+// spread through history; default list (warm + cold) and --branches (warm)
//
// Attribution: a `full` wall time can't be split by side (worktree- and
// branch-side git subprocesses overlap on the rayon pool), so to see where a
@@ -23,17 +21,19 @@
// cargo bench --bench list # All benchmarks
// cargo bench --bench list skeleton # Progressive rendering
// cargo bench --bench list full # Combined full-surface fixture
-// cargo bench --bench list real_repo_many_branches # GH #461 scenario (large repo + many branches)
+// cargo bench --bench list large_repository # Canonical large repo
// cargo bench --bench list warm # Warm-cache variants (every group's warm rows)
// cargo bench --bench list skeleton/warm # Skeleton group, warm only
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
+use std::cell::OnceCell;
use std::path::Path;
use wt_perf::{
- CacheState, FixtureRepo, RepoConfig, add_history_spread_branches, add_worktrees, bench_wt,
- clone_rust_repo, create_mixed_repo, create_repo, run_git, wt_command,
+ CacheState, FixtureRecipe, bench_wt, run_git, standard_benchmark_profile, wt_command,
};
+const WORKTREE_COUNTS: [usize; 3] = [1, 4, 8];
+
/// Run `wt` with `args` in `repo_path`, on a warm or cold cache.
///
/// Fixture-agnostic: callers build whatever repo shape they want, then pass
@@ -60,13 +60,13 @@ fn bench_skeleton(c: &mut Criterion) {
let mut group = c.benchmark_group("skeleton");
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- for worktrees in [1, 4, 8] {
+ for total_worktrees in WORKTREE_COUNTS {
for cache in CacheState::WARM_AND_COLD {
group.bench_with_input(
- BenchmarkId::new(cache.label(), worktrees),
+ BenchmarkId::new(cache.label(), total_worktrees),
&cache,
|b, &cache| {
- let fixture = create_repo(&RepoConfig::typical(worktrees));
+ let fixture = FixtureRecipe::Typical { total_worktrees }.create();
run_benchmark(
b,
binary,
@@ -87,13 +87,13 @@ fn bench_worktree_scaling(c: &mut Criterion) {
let mut group = c.benchmark_group("worktree_scaling");
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- for worktrees in [1, 4, 8] {
+ for total_worktrees in WORKTREE_COUNTS {
for cache in CacheState::WARM_AND_COLD {
group.bench_with_input(
- BenchmarkId::new(cache.label(), worktrees),
+ BenchmarkId::new(cache.label(), total_worktrees),
&cache,
|b, &cache| {
- let fixture = create_repo(&RepoConfig::typical(worktrees));
+ let fixture = FixtureRecipe::Typical { total_worktrees }.create();
run_git(fixture.path(), &["status"]);
run_benchmark(b, binary, fixture.path(), cache, &["list"], None);
},
@@ -104,43 +104,43 @@ fn bench_worktree_scaling(c: &mut Criterion) {
group.finish();
}
-fn bench_real_repo(c: &mut Criterion) {
- let mut group = c.benchmark_group("real_repo");
- // `wt list` on rust-lang/rust runs ~2s warm β€” dominated by one deep
- // `git for-each-ref %(ahead-behind:main)` walk β€” and several times
- // that for cold, where each iteration also rebuilds eight 59k-entry
- // indexes via `git status`. Warm-path variance is that slowest single
- // subprocess, not measurement noise, so the inherited 30-sample / 15s
- // default just burns time: at >1s/iter Criterion can't fit 30 samples
- // in 15s, so it runs 30 single-iteration samples regardless. 10 is
- // Criterion's minimum (`sample_size` < 10 panics).
+fn bench_large_repository(c: &mut Criterion) {
+ let mut group = c.benchmark_group("large_repository");
+ // On rust-lang/rust these rows take seconds. Variance is dominated by the
+ // slowest git history walk rather than measurement noise, so Criterion's
+ // minimum 10 samples is enough. All rows use one canonical state: eight
+ // worktrees and fifty branches spread through history.
//
- // 8 worktrees only: the worktree-count scaling shape is tracked at
- // criterion cadence by `worktree_scaling` (synthetic, 1/4/8); what's
- // unique here is real-repo magnitude and the cold penalty, which the
- // 8-worktree endpoints keep β€” each extra variant costs a fresh local
- // clone of rust-lang/rust plus its measurement window.
+ // Default `list` still captures the repository's refs and ahead/behind
+ // state, but creates tasks only for worktree rows. `--branches` adds every
+ // local branch row and its integration work. The default warm/cold pair
+ // measures the large-repository cache penalty; the warm `--branches` row
+ // covers the GH #461 history-depth workload without duplicating the warm
+ // default row.
group.measurement_time(std::time::Duration::from_secs(20));
group.sample_size(10);
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- let worktrees = 8;
-
- for cache in CacheState::WARM_AND_COLD {
+ let fixture = OnceCell::new();
+
+ // Cold goes last because it removes the commit graph. Each warm row has
+ // its own Criterion warm-up, so sharing the repository doesn't share the
+ // command-specific cache state being measured.
+ for (mode, cache, args) in [
+ ("default", CacheState::Warm, &["list"][..]),
+ ("branches", CacheState::Warm, &["list", "--branches"][..]),
+ ("default", CacheState::Cold, &["list"][..]),
+ ] {
group.bench_with_input(
- BenchmarkId::new(cache.label(), worktrees),
+ BenchmarkId::new(mode, cache.label()),
&cache,
|b, &cache| {
- let config = RepoConfig::typical(worktrees);
- let fixture = clone_rust_repo();
- add_worktrees(&config, fixture.path());
- run_git(fixture.path(), &["status"]);
-
- bench_wt(b, fixture.path(), cache, || {
- let mut cmd = wt_command(binary, fixture.path(), None);
- cmd.arg("list");
- cmd
+ let fixture = fixture.get_or_init(|| {
+ let fixture = FixtureRecipe::LargeRepository.create();
+ run_git(fixture.path(), &["status"]);
+ fixture
});
+ run_benchmark(b, binary, fixture.path(), cache, args, None);
},
);
}
@@ -157,7 +157,7 @@ fn bench_divergent_branches(c: &mut Criterion) {
for cache in CacheState::WARM_AND_COLD {
group.bench_function(cache.label(), |b| {
- let fixture = create_repo(&RepoConfig::many_divergent_branches());
+ let fixture = FixtureRecipe::SyntheticDivergence.create();
run_git(fixture.path(), &["status"]);
run_benchmark(
b,
@@ -173,91 +173,12 @@ fn bench_divergent_branches(c: &mut Criterion) {
group.finish();
}
-/// Set up rust repo workspace with branches at different history depths.
-fn setup_rust_workspace_with_branches(num_branches: usize) -> FixtureRepo {
- let fixture = clone_rust_repo();
- add_history_spread_branches(fixture.path(), num_branches);
- run_git(fixture.path(), &["status"]);
- fixture
-}
-
-/// Benchmark GH #461 scenario: large real repo (rust-lang/rust) with branches at different
-/// historical points.
-///
-/// This reproduces the `wt switch` interactive picker delay reported in #461. The key factor
-/// is NOT commits per branch, but rather how far back in history branches diverge from each other.
-///
-/// Benchmarks two modes:
-/// - `warm`: with all branches (first run expensive, subsequent runs hit the persistent cache)
-/// - `warm_worktrees_only`: no branch enumeration (~600ms)
-///
-/// Key insight: `git for-each-ref %(ahead-behind:BASE)` is O(commits), not O(refs).
-/// It must walk the commit graph to compute divergence, so it takes ~2s on rust-lang/rust
-/// regardless of how many refs are queried. Skipping branch enumeration entirely avoids this.
-fn bench_real_repo_many_branches(c: &mut Criterion) {
- let mut group = c.benchmark_group("real_repo_many_branches");
- // rust-lang/rust runs ~3.7s per `wt list --branches` iteration; warm-path
- // variance is dominated by the slowest single subprocess (a deep
- // `git merge-base` walking history), not measurement noise, so 10 samples
- // (criterion's minimum β€” `sample_size` < 10 panics) suffices. A 20s budget
- // is β‰ˆ one iteration per sample (~37s/function), down from the
- // ~74s/function criterion spent filling the old 60s budget.
- group.measurement_time(std::time::Duration::from_secs(20));
- group.sample_size(10);
-
- let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
-
- // Setup function - each bench_function creates its own fresh workspace
- // Uses setup_rust_workspace_with_branches plus a worktree for worktrees_only test
- let setup_workspace = || {
- let fixture = setup_rust_workspace_with_branches(50);
-
- // Add a second worktree (needed for worktrees_only to not auto-show branches)
- let wt_path = fixture.root().join("wt-test");
- run_git(
- fixture.path(),
- &[
- "worktree",
- "add",
- "-b",
- "test-worktree",
- wt_path.to_str().unwrap(),
- "HEAD",
- ],
- );
-
- fixture
- };
-
- // Baseline: all branches
- group.bench_function("warm", |b| {
- let fixture = setup_workspace();
- bench_wt(b, fixture.path(), CacheState::Warm, || {
- let mut cmd = wt_command(binary, fixture.path(), None);
- cmd.args(["list", "--branches"]);
- cmd
- });
- });
-
- // Worktrees only: no branch enumeration, skips expensive %(ahead-behind) batch
- group.bench_function("warm_worktrees_only", |b| {
- let fixture = setup_workspace();
- bench_wt(b, fixture.path(), CacheState::Warm, || {
- let mut cmd = wt_command(binary, fixture.path(), None);
- cmd.arg("list"); // no --branches
- cmd
- });
- });
-
- group.finish();
-}
-
/// Combined full-surface `wt list`: many worktrees AND many branches in varied
/// states, with branch divergence spread across history depth β€” the whole
/// command exercised by one fixture instead of several narrow ones. This is the
/// realistic "lots of worktrees & branches, all in various states" workload.
///
-/// `create_mixed_repo` builds the spread of `wt list` gates and tasks at once:
+/// [`FixtureRecipe::Mixed`] builds the spread of `wt list` gates and tasks at once:
/// clean/dirty/staged working trees, merged/ahead/diverged branches, and the
/// GH #461 deep-divergence shape (branches forking at points spread across
/// history depth, so the `git for-each-ref %(ahead-behind)` walk has real
@@ -293,11 +214,16 @@ fn bench_full(c: &mut Criterion) {
group.sample_size(10);
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- let (worktrees, branches) = (24usize, 120usize);
+ let (linked_worktrees, branchless_branches) = (24usize, 120usize);
for cache in CacheState::WARM_AND_COLD {
group.bench_function(cache.label(), |b| {
- let fixture = create_mixed_repo(worktrees, branches, 0);
+ let fixture = FixtureRecipe::Mixed {
+ linked_worktrees,
+ branchless_branches,
+ remote_tracking_refs: 0,
+ }
+ .create();
run_benchmark(
b,
binary,
@@ -314,10 +240,7 @@ fn bench_full(c: &mut Criterion) {
criterion_group! {
name = benches;
- config = Criterion::default()
- .sample_size(30)
- .measurement_time(std::time::Duration::from_secs(15))
- .warm_up_time(std::time::Duration::from_secs(3));
- targets = bench_skeleton, bench_worktree_scaling, bench_full, bench_real_repo, bench_divergent_branches, bench_real_repo_many_branches
+ config = standard_benchmark_profile();
+ targets = bench_skeleton, bench_worktree_scaling, bench_full, bench_large_repository, bench_divergent_branches
}
criterion_main!(benches);
diff --git a/benches/picker_preview.rs b/benches/picker_preview.rs
index 056caacfe..dedc4eb33 100644
--- a/benches/picker_preview.rs
+++ b/benches/picker_preview.rs
@@ -39,7 +39,7 @@
#[cfg(not(unix))]
fn main() {
- // Picker is Unix-only; benchmark is a no-op on Windows.
+ // This benchmark is intentionally a no-op on Windows.
}
#[cfg(unix)]
@@ -47,7 +47,7 @@ use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
#[cfg(unix)]
use std::path::Path;
#[cfg(unix)]
-use wt_perf::{CacheState, RepoConfig, bench_wt, create_repo, wt_command};
+use wt_perf::{CacheState, FixtureRecipe, bench_wt, wt_command};
#[cfg(unix)]
fn bench_picker_preview(c: &mut Criterion) {
@@ -62,14 +62,14 @@ fn bench_picker_preview(c: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(35));
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- let worktrees = 8;
+ let total_worktrees = 8;
for cache in CacheState::WARM_AND_COLD {
group.bench_with_input(
- BenchmarkId::new(cache.label(), format!("typical-{worktrees}")),
+ BenchmarkId::new(cache.label(), format!("typical-{total_worktrees}")),
&cache,
|b, &cache| {
- let fixture = create_repo(&RepoConfig::typical(worktrees));
+ let fixture = FixtureRecipe::Typical { total_worktrees }.create();
let make_cmd = || {
let mut cmd = wt_command(binary, fixture.path(), None);
diff --git a/benches/prune.rs b/benches/prune.rs
index 17fb358ee..0f8b7649d 100644
--- a/benches/prune.rs
+++ b/benches/prune.rs
@@ -11,7 +11,7 @@
// delete) serially under the write side of the scan lock, reusing the
// removal plan its scan check computed.
//
-// The fixture is `wt_perf::create_prune_repo`: squash-merged candidates
+// The fixture is `wt_perf::FixtureRecipe::Prune`: squash-merged candidates
// (integrated by content β€” the expensive probe path, the post-PR-squash shape
// prune typically removes) against a two-sided-diverged backdrop of unmerged
// worktrees and branches (forked deep in history while main advanced) that
@@ -23,35 +23,37 @@
// new commits on main" shape; git's own caches
// stay warm, as after a real fetch)
// - prune_e2e/dry_run_warm β€” full scan, caches warm (steady-state re-run)
-// - prune_e2e/live β€” scan + removal of the squash-merged candidates,
-// which are re-created before every iteration
-// - prune_real_repo/ β€” the same probe-cold and warm dry-runs on a
-// dry_run_probe_cold, rust-lang/rust clone with both populations at
-// dry_run_warm "dozens of worktrees" scale (cached ~15 GiB
+// - prune_e2e/live β€” scan + removal of the squash-merged candidates
+// from a fresh fixture per sample
+// - prune_large_repository/ β€” the same probe-cold and warm dry-runs on a
+// dry_run_probe_cold, pinned large-repository corpus with both
+// dry_run_warm populations at "dozens of worktrees" scale (~15 GiB
// fixture; first-ever run clones, minutes).
-// Opt-in via `--features real-repo-benches` so
+// Opt-in via `--features large-repository-benches` so
// the daily CI benchmarks job never builds it;
// full-cold and live at this scale are one-shot
// timelines, not criterion groups (see below)
//
// Run examples:
// cargo bench --bench prune # Synthetic variants
-// cargo bench --bench prune --features real-repo-benches prune_real_repo
+// cargo bench --bench prune --features large-repository-benches prune_large_repository
//
// For phase attribution (scan vs per-candidate removal), trace one invocation
-// instead: `wt-perf setup prune-4-8 --path /tmp/prune-repo`, then
+// instead: `wt-perf setup prune 4 8 --path /tmp/prune-repo`, then
// `wt-perf timeline -- -C /tmp/prune-repo step prune --dry-run --min-age 0s`
// and read the `prune-gather` / `prune-scan` / `prune-check:*` /
// `prune-remove:*` spans.
-use std::cell::Cell;
+use std::cell::OnceCell;
use std::path::Path;
use std::process::Command;
+use std::time::{Duration, Instant};
use criterion::{Criterion, criterion_group, criterion_main};
use wt_perf::{
- CacheState, PRUNE_REAL_MERGED, PRUNE_REAL_UNMERGED, add_squash_merged, bench_wt,
- create_prune_repo, ensure_prune_real_repo, run_and_check, wt_command,
+ CacheState, FixtureRecipe, PRUNE_LARGE_REPOSITORY_BACKDROP_PAIRS,
+ PRUNE_LARGE_REPOSITORY_CANDIDATE_PAIRS, bench_wt, invalidate_probe_caches,
+ linked_worktree_path, run_and_check, run_git_ok, wt_command,
};
/// Squash-merged candidates per population (worktrees and orphan branches) β€”
@@ -85,10 +87,8 @@ fn wt_cmd(repo: &Path, args: &[&str]) -> Command {
/// fixture whose candidates prune doesn't detect, and detection false
/// positives against the unmerged backdrop (this once caught an invalidation
/// deleting worktree indexes and silently flipping the removability gate).
-/// The timed iterations themselves assert only exit status (`bench_wt`); a
-/// live run that removes nothing surfaces on the next iteration's
-/// re-creation instead β€” branch names don't carry the round, so
-/// `add_squash_merged` fails loudly on the collision.
+/// The timed iterations themselves assert only exit status (`bench_wt`); the
+/// live fixture checks the destructive postcondition after timing.
fn verify_candidates(repo: &Path, expected: usize) {
let output = run_and_check(&mut wt_cmd(repo, DRY_RUN_ARGS));
let items: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
@@ -99,122 +99,158 @@ fn verify_candidates(repo: &Path, expected: usize) {
);
}
+fn assert_branch(repo: &Path, branch: &str, expected: bool) {
+ assert_eq!(
+ run_git_ok(
+ repo,
+ &[
+ "show-ref",
+ "--verify",
+ "--quiet",
+ &format!("refs/heads/{branch}")
+ ]
+ ),
+ expected,
+ "branch {branch} presence differed from the live-prune fixture contract"
+ );
+}
+
+fn assert_live_result(repo: &Path) {
+ verify_candidates(repo, 0);
+ for i in 0..MERGED {
+ let worktree_branch = format!("merged-wt-{i}");
+ let branch = format!("merged-br-{i}");
+ assert!(
+ !linked_worktree_path(repo, &worktree_branch).exists(),
+ "measured prune left candidate worktree {worktree_branch}"
+ );
+ assert_branch(repo, &worktree_branch, false);
+ assert_branch(repo, &branch, false);
+ }
+ for i in 0..UNMERGED {
+ let worktree_branch = format!("feature-wt-{i}");
+ let branch = format!("feature-{i:03}");
+ assert!(
+ linked_worktree_path(repo, &worktree_branch).is_dir(),
+ "measured prune removed backdrop worktree {worktree_branch}"
+ );
+ assert_branch(repo, &worktree_branch, true);
+ assert_branch(repo, &branch, true);
+ }
+}
+
fn bench_prune_e2e(c: &mut Criterion) {
let mut group = c.benchmark_group("prune_e2e");
// Dry-run repo: candidates present but never removed, so the fixture is
// reusable across iterations without re-setup.
- let dry_fixture = create_prune_repo(MERGED, UNMERGED);
+ let dry_fixture = FixtureRecipe::Prune {
+ candidate_pairs: MERGED,
+ backdrop_pairs: UNMERGED,
+ }
+ .create();
verify_candidates(dry_fixture.path(), MERGED * 2);
- // Probe-cold: every iteration re-pays the integration probes that
- // sha_cache would otherwise absorb β€” the "first prune after fetching
- // main" cost, with git's own caches staying warm as after a real fetch.
- group.bench_function("dry_run_probe_cold", |b| {
- bench_wt(b, dry_fixture.path(), CacheState::ProbeCold, || {
- wt_cmd(dry_fixture.path(), DRY_RUN_ARGS)
+ for (id, cache) in [
+ // First prune after fetching the default branch.
+ ("dry_run_probe_cold", CacheState::ProbeCold),
+ // Steady-state re-scan where every probe hits sha_cache.
+ ("dry_run_warm", CacheState::Warm),
+ ] {
+ group.bench_function(id, |b| {
+ bench_wt(b, dry_fixture.path(), cache, || {
+ wt_cmd(dry_fixture.path(), DRY_RUN_ARGS)
+ });
});
- });
-
- // Warm: the steady-state re-scan where every probe hits sha_cache.
- group.bench_function("dry_run_warm", |b| {
- bench_wt(b, dry_fixture.path(), CacheState::Warm, || {
- wt_cmd(dry_fixture.path(), DRY_RUN_ARGS)
- });
- });
+ }
- // Live: scan + removal. The repo starts with no candidates (merged = 0);
- // each iteration's setup adds a fresh round of squash-merged worktrees
- // and branches, and the measured run removes them. `round` uniquifies the
- // committed content β€” re-using a round's files would make the squash
- // merge empty and the setup commit fail.
- //
- // Re-creation right after removal is safe without waiting for the
- // detached `rm -rf`: prune stages the worktree into `.git/wt/trash/`
- // (rename), prunes metadata, and CAS-deletes the branch synchronously
- // before it exits, so path and branch name are free; the background rm
- // only ever touches the staged trash entry. (Contrast with
- // `benches/remove.rs`, which removes the *current* worktree β€” that path
- // leaves a placeholder directory plus a background `rmdir` that would
- // race the recreation.)
- let live_fixture = create_prune_repo(0, UNMERGED);
- verify_candidates(live_fixture.path(), 0);
- let round = Cell::new(0usize);
-
- // Setup here is candidate re-creation, not invalidation, so this arm
- // can't go through `bench_wt` β€” the same carve-out as `remove_e2e`.
+ // Live: build and validate a fresh owned fixture outside each measured
+ // duration. This avoids mutable template refs and repair logic while
+ // preserving the exact candidate/backdrop contract.
group.bench_function("live", |b| {
- b.iter_batched(
- || {
- add_squash_merged(live_fixture.path(), MERGED, round.get());
- round.set(round.get() + 1);
- },
- |_| {
- run_and_check(&mut wt_cmd(live_fixture.path(), LIVE_ARGS));
- },
- criterion::BatchSize::PerIteration,
- );
+ b.iter_custom(|iterations| {
+ let mut measured = Duration::ZERO;
+ for _ in 0..iterations {
+ let fixture = FixtureRecipe::Prune {
+ candidate_pairs: MERGED,
+ backdrop_pairs: UNMERGED,
+ }
+ .create();
+ verify_candidates(fixture.path(), MERGED * 2);
+ invalidate_probe_caches(fixture.path());
+
+ let started = Instant::now();
+ run_and_check(&mut wt_cmd(fixture.path(), LIVE_ARGS));
+ measured += started.elapsed();
+ assert_live_result(fixture.path());
+ }
+ measured
+ });
});
group.finish();
}
-/// Rust-lang/rust-scale scan ([`ensure_prune_real_repo`]): a 331k-commit repo
+/// Large-repository scan: a 331k-commit repo
/// with 12 squash-merged candidate pairs against a two-sided-diverged
/// backdrop of 24 worktrees + 24 orphan branches forked across the last 5000
/// commits β€” 36 linked worktrees, lots removable, more not. Scale is what
/// moves every per-item cost β€” `merge-base --is-ancestor` ~40 ms, `merge-tree
/// --write-tree` ~130 ms, `git status` over ~60k files β€” vs the synthetic
-/// fixture where probes bottom out at subprocess spawn. First run clones
-/// rust-lang/rust from the network (minutes), then builds ~36 worktrees at
-/// ~3 s each; both are cached under target/wt-perf/bench-repos across runs.
+/// fixture where probes bottom out at subprocess spawn. The pinned source is
+/// cached; each benchmark process builds one fresh ~36-worktree fixture.
///
/// Dry-runs only, in two flavors: warm (steady-state re-scan) and probe-cold
/// (`.git/wt/cache/` cleared per iteration β€” the "first prune after fetching
/// main" shape, where probes re-run at real cost but statuses stay
-/// stat-warm). Probe-cold is criterion-feasible precisely because the
-/// invalidation leaves the indexes alone; a *full*-cold iteration deletes
-/// indexes and must rebuild them via `git reset` (a missing index reads as
-/// all-tracked-files-deleted), and the rebuilt indexes carry no stat data,
-/// so all 36 statuses re-hash ~60k files β€” ~1 min per iteration, turning
-/// criterion's 10-sample minimum into a ~10-minute benchmark of a
-/// mostly-artificial state. A live iteration would consume
-/// the candidates and pay a minutes-long re-creation per sample. Measure
-/// full-cold and live at this scale as one-shots instead (`wt-perf setup
-/// prune-real`, then `wt-perf timeline -- -C <repo> step prune --min-age
-/// 0s`); the next `ensure_prune_real_repo` call repairs the consumed
-/// candidates.
-fn bench_prune_real_repo(c: &mut Criterion) {
- // Opt-in only (`--features real-repo-benches`): the fixture is ~15 GiB β€”
+/// stat-warm). A full-cold scan and live removal are one-shot timeline
+/// workloads at this scale: the former adds commit-graph rebuilding to the
+/// probe cost, while the latter consumes its fixture. Use `wt-perf setup
+/// large-repository-prune 12 24 --path <new-path>` for either.
+fn bench_prune_large_repository(c: &mut Criterion) {
+ // Opt-in only (`--features large-repository-benches`): the fixture is ~15 GiB β€”
// bigger than a hosted CI runner's disk and the actions cache cap β€” so
// the daily benchmarks workflow (plain `cargo bench`) must never build
// it. `cfg!` keeps the body compiling either way.
- if !cfg!(feature = "real-repo-benches") {
+ if !cfg!(feature = "large-repository-benches") {
return;
}
- let mut group = c.benchmark_group("prune_real_repo");
+ let mut group = c.benchmark_group("prune_large_repository");
+ let fixture = OnceCell::new();
group.bench_function("dry_run_warm", |b| {
// Built inside the closure: criterion invokes a bench closure only
// when the CLI filter matches it, but runs this function (and any
// eager setup in it) unconditionally. This keeps a filtered run
- // (`cargo bench --bench prune prune_e2e`) from cloning
- // rust-lang/rust β€” or worse, racing a concurrent `wt-perf setup
- // prune-real` and wiping the fixture it is mid-build. Repeat
- // invocations re-validate the cached fixture in a few git commands.
- let repo = ensure_prune_real_repo(PRUNE_REAL_MERGED, PRUNE_REAL_UNMERGED);
- verify_candidates(&repo, PRUNE_REAL_MERGED * 2);
- bench_wt(b, &repo, CacheState::Warm, || wt_cmd(&repo, DRY_RUN_ARGS));
+ // (`cargo bench --bench prune prune_e2e`) from cloning the large
+ // corpus. Both variants share the fresh fixture when both match.
+ let fixture = fixture.get_or_init(|| {
+ FixtureRecipe::LargeRepositoryPrune {
+ candidate_pairs: PRUNE_LARGE_REPOSITORY_CANDIDATE_PAIRS,
+ backdrop_pairs: PRUNE_LARGE_REPOSITORY_BACKDROP_PAIRS,
+ }
+ .create()
+ });
+ let repo = fixture.path();
+ verify_candidates(repo, PRUNE_LARGE_REPOSITORY_CANDIDATE_PAIRS * 2);
+ bench_wt(b, repo, CacheState::Warm, || wt_cmd(repo, DRY_RUN_ARGS));
});
group.bench_function("dry_run_probe_cold", |b| {
// Built inside the closure for the same filter-matching reason as
- // dry_run_warm above; a second call re-validates cheaply.
- let repo = ensure_prune_real_repo(PRUNE_REAL_MERGED, PRUNE_REAL_UNMERGED);
- verify_candidates(&repo, PRUNE_REAL_MERGED * 2);
- bench_wt(b, &repo, CacheState::ProbeCold, || {
- wt_cmd(&repo, DRY_RUN_ARGS)
+ // dry_run_warm above.
+ let fixture = fixture.get_or_init(|| {
+ FixtureRecipe::LargeRepositoryPrune {
+ candidate_pairs: PRUNE_LARGE_REPOSITORY_CANDIDATE_PAIRS,
+ backdrop_pairs: PRUNE_LARGE_REPOSITORY_BACKDROP_PAIRS,
+ }
+ .create()
+ });
+ let repo = fixture.path();
+ verify_candidates(repo, PRUNE_LARGE_REPOSITORY_CANDIDATE_PAIRS * 2);
+ bench_wt(b, repo, CacheState::ProbeCold, || {
+ wt_cmd(repo, DRY_RUN_ARGS)
});
});
@@ -227,6 +263,6 @@ criterion_group! {
.sample_size(10)
.measurement_time(std::time::Duration::from_secs(20))
.warm_up_time(std::time::Duration::from_secs(3));
- targets = bench_prune_e2e, bench_prune_real_repo
+ targets = bench_prune_e2e, bench_prune_large_repository
}
criterion_main!(benches);
diff --git a/benches/remove.rs b/benches/remove.rs
index 7628180fb..a5453426d 100644
--- a/benches/remove.rs
+++ b/benches/remove.rs
@@ -4,124 +4,211 @@
// spawning, to complement `first_output/remove` in `time_to_first_output`,
// which exits before output.
//
-// Benchmark variants:
-// - remove_e2e/no_hooks β€” remove with --no-hooks (no hook loading)
-// - remove_e2e/with_hooks β€” remove with hooks configured (user + project)
+// Both variants use the same project and user hook configuration:
+// - remove_e2e/no_hooks β€” the hooks are bypassed with --no-hooks
+// - remove_e2e/with_hooks β€” the hooks are approved and spawned
//
// Run examples:
// cargo bench --bench remove # All variants
// cargo bench --bench remove -- no_hooks # Just no-hooks variant
+use std::path::{Path, PathBuf};
+use std::time::{Duration, Instant};
+
use criterion::{Criterion, criterion_group, criterion_main};
-use std::path::Path;
use wt_perf::{
- FixtureRepo, RepoConfig, create_repo, linked_worktree_path, run_and_check, run_git, run_git_ok,
- wt_command,
+ FixtureRecipe, FixtureRepo, add_typical_linked_worktrees, linked_worktree_path, run_and_check,
+ run_git, run_git_ok, setup_fake_remote, wt_command,
};
-/// Create an owned benchmark repo with optional hooks.
-fn create_bench_repo(with_hooks: bool) -> FixtureRepo {
- let config = RepoConfig::typical(2); // main + 1 feature worktree
- let fixture = create_repo(&config);
+const BRANCH: &str = "feature-wt-1";
+const UNTRACKED_FILES: usize = 3;
+const BACKGROUND_TIMEOUT: Duration = Duration::from_secs(10);
+const POLL_INTERVAL: Duration = Duration::from_millis(20);
+
+struct RemoveFixture {
+ repo: FixtureRepo,
+ user_config: PathBuf,
+ project_marker: PathBuf,
+ user_marker: PathBuf,
+ worktree_admin_dir: PathBuf,
+}
+
+impl RemoveFixture {
+ /// Build one complete candidate outside the measured duration.
+ fn create(binary: &Path) -> Self {
+ let repo = FixtureRecipe::Typical { total_worktrees: 1 }.create();
+ let project_marker = repo.root().join("project-post-remove.marker");
+ let user_marker = repo.root().join("user-post-switch.marker");
- if with_hooks {
- // Project config with post-remove hook
- let config_dir = fixture.path().join(".config");
+ let config_dir = repo.path().join(".config");
std::fs::create_dir_all(&config_dir).unwrap();
std::fs::write(
config_dir.join("wt.toml"),
- "[post-remove]\ndocs = \"echo post-remove-done\"\n",
+ format!(
+ "[post-remove]\nbenchmark = \"{}\"\n",
+ marker_command(&project_marker, "project")
+ ),
)
.unwrap();
- run_git(fixture.path(), &["add", "."]);
- run_git(fixture.path(), &["commit", "-m", "Add project config"]);
- }
+ run_git(repo.path(), &["add", ".config/wt.toml"]);
+ run_git(repo.path(), &["commit", "-m", "Add benchmark hook"]);
- fixture
-}
+ add_typical_linked_worktrees(repo.path(), 1);
+ setup_fake_remote(repo.path());
+ let worktree_admin_dir = linked_worktree_admin_dir(&repo.worktree_path(BRANCH));
-/// Recreate the feature worktree after it was removed.
-fn recreate_worktree(repo_path: &Path) {
- let wt_path = linked_worktree_path(repo_path, "feature-wt-1");
+ let user_config = repo.root().join("config.toml");
+ std::fs::write(
+ &user_config,
+ format!(
+ "[post-switch]\nbenchmark = \"{}\"\n",
+ marker_command(&user_marker, "user")
+ ),
+ )
+ .unwrap();
- // Wait briefly for background removal to finish (sleep 1 + rm -rf in detached process).
- // Without this, the background rmdir/rm-rf races with worktree recreation.
- std::thread::sleep(std::time::Duration::from_millis(1200));
+ let fixture = Self {
+ repo,
+ user_config,
+ project_marker,
+ user_marker,
+ worktree_admin_dir,
+ };
+ for i in 0..UNTRACKED_FILES {
+ assert!(
+ fixture
+ .worktree_path()
+ .join(format!("uncommitted_{i}.txt"))
+ .is_file(),
+ "remove fixture untracked payload {i} is missing"
+ );
+ }
+ fixture.prewarm(binary);
+ fixture
+ }
- // Clean up any leftover directory (placeholder or staged trash)
- let _ = std::fs::remove_dir_all(&wt_path);
+ fn worktree_path(&self) -> PathBuf {
+ linked_worktree_path(self.repo.path(), BRANCH)
+ }
- // Clean up trash directory from staged removals
- let trash_dir = repo_path.join(".git/wt/trash");
- if trash_dir.exists() {
- let _ = std::fs::remove_dir_all(&trash_dir);
+ /// Preserve the original cache-warm remove scenario without reusing a
+ /// mutable fixture. Prune's dry-run uses the same integration probes and
+ /// cannot consume the unmerged candidate.
+ fn prewarm(&self, binary: &Path) {
+ let mut cmd = wt_command(binary, self.repo.path(), Some(&self.user_config));
+ cmd.args([
+ "step",
+ "prune",
+ "--dry-run",
+ "--min-age",
+ "0s",
+ "--format",
+ "json",
+ ]);
+ run_and_check(&mut cmd);
}
- // Prune stale worktree metadata (best-effort)
- let _ = run_git_ok(repo_path, &["worktree", "prune"]);
-
- // Delete branch if it exists (may already be deleted by removal)
- let _ = run_git_ok(repo_path, &["branch", "-D", "feature-wt-1"]);
-
- // Recreate branch + worktree
- run_git(
- repo_path,
- &[
- "worktree",
- "add",
- "-b",
- "feature-wt-1",
- wt_path.to_str().unwrap(),
- "HEAD",
- ],
- );
+ /// Wait for current-worktree cleanup and detached hooks to settle, then
+ /// check both the destructive result and the hook-control contract.
+ fn assert_consumed(&self, expect_hooks: bool) {
+ let worktree = self.worktree_path();
+ wait_for("remove background cleanup and hooks", || {
+ let hooks_finished =
+ !expect_hooks || (self.project_marker.is_file() && self.user_marker.is_file());
+ !worktree.exists() && hooks_finished
+ });
+
+ assert!(
+ run_git_ok(
+ self.repo.path(),
+ &[
+ "show-ref",
+ "--verify",
+ "--quiet",
+ &format!("refs/heads/{BRANCH}")
+ ]
+ ),
+ "measured remove deleted the retained candidate branch"
+ );
+ assert!(
+ !self.worktree_admin_dir.exists(),
+ "measured remove left the worktree registration behind"
+ );
+
+ if expect_hooks {
+ assert_eq!(
+ std::fs::read_to_string(&self.project_marker).unwrap(),
+ "project"
+ );
+ assert_eq!(std::fs::read_to_string(&self.user_marker).unwrap(), "user");
+ } else {
+ assert!(
+ !self.project_marker.exists() && !self.user_marker.exists(),
+ "--no-hooks unexpectedly produced a hook marker"
+ );
+ }
+ }
}
-fn bench_remove_e2e(c: &mut Criterion) {
- let mut group = c.benchmark_group("remove_e2e");
- let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
+fn marker_command(path: &Path, value: &str) -> String {
+ format!(
+ "printf {value} > {}",
+ shell_escape::unix::escape(path.to_string_lossy())
+ )
+}
- let repo_no_hooks = create_bench_repo(false);
- let repo_with_hooks = create_bench_repo(true);
+fn linked_worktree_admin_dir(worktree: &Path) -> PathBuf {
+ let dot_git = std::fs::read_to_string(worktree.join(".git")).unwrap();
+ let git_dir = dot_git
+ .trim()
+ .strip_prefix("gitdir: ")
+ .expect("linked worktree .git file must contain a gitdir");
+ PathBuf::from(git_dir)
+}
- // User config with post-switch hook (written beside repo)
- let user_config_no_hooks = repo_no_hooks.root().join("config.toml");
- std::fs::write(&user_config_no_hooks, "").unwrap();
+fn wait_for(label: &str, mut condition: impl FnMut() -> bool) {
+ let deadline = Instant::now() + BACKGROUND_TIMEOUT;
+ while !condition() {
+ assert!(Instant::now() < deadline, "timed out waiting for {label}");
+ std::thread::sleep(POLL_INTERVAL);
+ }
+}
- let user_config_with_hooks = repo_with_hooks.root().join("config.toml");
- std::fs::write(
- &user_config_with_hooks,
- "[hooks.post-switch]\nzellij-tab = \"echo post-switch-done\"\n",
- )
- .unwrap();
-
- // No hooks: --no-hooks (skip hook loading), run from feature worktree
- group.bench_function("no_hooks", |b| {
- b.iter_batched(
- || recreate_worktree(repo_no_hooks.path()),
- |()| {
- let wt_path = repo_no_hooks.worktree_path("feature-wt-1");
- let mut cmd = wt_command(binary, &wt_path, Some(&user_config_no_hooks));
- cmd.args(["remove", "--yes", "--no-hooks", "--force"]);
- run_and_check(&mut cmd);
- },
- criterion::BatchSize::PerIteration,
- );
- });
+fn bench_variant(
+ group: &mut criterion::BenchmarkGroup<'_, criterion::measurement::WallTime>,
+ name: &str,
+ expect_hooks: bool,
+) {
+ let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- // With hooks: user post-switch + project post-remove
- group.bench_function("with_hooks", |b| {
- b.iter_batched(
- || recreate_worktree(repo_with_hooks.path()),
- |()| {
- let wt_path = repo_with_hooks.worktree_path("feature-wt-1");
- let mut cmd = wt_command(binary, &wt_path, Some(&user_config_with_hooks));
+ group.bench_function(name, |b| {
+ b.iter_custom(|iterations| {
+ let mut measured = Duration::ZERO;
+ for _ in 0..iterations {
+ let fixture = RemoveFixture::create(binary);
+ let worktree = fixture.worktree_path();
+ let mut cmd = wt_command(binary, &worktree, Some(&fixture.user_config));
cmd.args(["remove", "--yes", "--force"]);
+ if !expect_hooks {
+ cmd.arg("--no-hooks");
+ }
+
+ let started = Instant::now();
run_and_check(&mut cmd);
- },
- criterion::BatchSize::PerIteration,
- );
+ measured += started.elapsed();
+ fixture.assert_consumed(expect_hooks);
+ }
+ measured
+ });
});
+}
+
+fn bench_remove_e2e(c: &mut Criterion) {
+ let mut group = c.benchmark_group("remove_e2e");
+
+ bench_variant(&mut group, "no_hooks", false);
+ bench_variant(&mut group, "with_hooks", true);
group.finish();
}
@@ -129,9 +216,9 @@ fn bench_remove_e2e(c: &mut Criterion) {
criterion_group! {
name = benches;
config = Criterion::default()
- .sample_size(20)
- .measurement_time(std::time::Duration::from_secs(20))
- .warm_up_time(std::time::Duration::from_secs(3));
+ .sample_size(10)
+ .measurement_time(std::time::Duration::from_secs(3))
+ .warm_up_time(std::time::Duration::from_secs(1));
targets = bench_remove_e2e
}
criterion_main!(benches);
diff --git a/benches/time_to_first_output.rs b/benches/time_to_first_output.rs
index d36eabb75..2e1d36243 100644
--- a/benches/time_to_first_output.rs
+++ b/benches/time_to_first_output.rs
@@ -15,14 +15,15 @@
use criterion::{Criterion, criterion_group, criterion_main};
use std::path::Path;
-use wt_perf::{CacheState, RepoConfig, bench_wt, create_repo, run_and_check, wt_command};
+use wt_perf::{
+ CacheState, FixtureRecipe, bench_wt, run_and_check, standard_benchmark_profile, wt_command,
+};
fn bench_first_output(c: &mut Criterion) {
let mut group = c.benchmark_group("first_output");
let binary = Path::new(env!("CARGO_BIN_EXE_wt"));
- let config = RepoConfig::typical(4);
- let fixture = create_repo(&config);
+ let fixture = FixtureRecipe::Typical { total_worktrees: 4 }.create();
let make_cmd = |args: &[&str]| {
let mut cmd = wt_command(binary, fixture.path(), None);
@@ -53,14 +54,13 @@ fn bench_first_output(c: &mut Criterion) {
// list: stdout is piped here, so first output is the first buffered table
// line after collection/render preparation, not the progressive skeleton.
+ let output = run_and_check(&mut make_cmd(&["list"]));
+ assert!(
+ !output.stdout.is_empty(),
+ "WORKTRUNK_FIRST_OUTPUT should emit the first stdout line"
+ );
group.bench_function("list", |b| {
- b.iter(|| {
- let output = run_and_check(&mut make_cmd(&["list"]));
- assert!(
- !output.stdout.is_empty(),
- "WORKTRUNK_FIRST_OUTPUT should emit the first stdout line"
- );
- });
+ b.iter(|| run_and_check(&mut make_cmd(&["list"])));
});
group.finish();
@@ -68,10 +68,7 @@ fn bench_first_output(c: &mut Criterion) {
criterion_group! {
name = benches;
- config = Criterion::default()
- .sample_size(30)
- .measurement_time(std::time::Duration::from_secs(15))
- .warm_up_time(std::time::Duration::from_secs(3));
+ config = standard_benchmark_profile();
targets = bench_first_output
}
criterion_main!(benches);
diff --git a/flake.nix b/flake.nix
index 106ac2563..6017ea792 100644
--- a/flake.nix
+++ b/flake.nix
@@ -40,10 +40,10 @@
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
- # Filter source to include Cargo files plus templates (needed by askama)
- # and the Gemini extension manifest (embedded via include_str! in
- # src/testing/mod.rs; lives at the repo root because Gemini's loader
- # reads it only from the clone root β€” see #2807).
+ # Filter source to include Cargo files, askama templates, and compile-time data.
+ # Gemini's loader requires its manifest at the repo root (see #2807).
+ # The benchmark fixture definition stays extensionless so Cargo does not
+ # auto-discover it as a bench target.
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
@@ -53,7 +53,8 @@
|| (baseNameOf (dirOf p) == "templates")
|| (pkgs.lib.hasInfix "/dev/" p)
|| (baseNameOf (dirOf p) == "dev")
- || (baseNameOf p == "gemini-extension.json");
+ || (baseNameOf p == "gemini-extension.json")
+ || (baseNameOf p == "large-repository-fixture");
};
# Common arguments for crane builds
diff --git a/src/commands/CLAUDE.md b/src/commands/CLAUDE.md
index 550b29cc6..fc81bc6a5 100644
--- a/src/commands/CLAUDE.md
+++ b/src/commands/CLAUDE.md
@@ -7,10 +7,11 @@ When debugging TUI commands like `wt switch` (interactive picker), use the `tmux
### 1. Create Test Environment
```bash
-cargo run -p wt-perf -- setup picker-test
+cargo run -p wt-perf -- setup mixed 5 2 0 --path /tmp/wt-picker-test
```
-This creates a reproducible test repo at `target/wt-perf/picker-test/` (under the workspace root, reaped by `cargo clean`). `wt-perf setup` also prints the exact path.
+This creates a varied repository with linked worktrees and branch-only rows for
+the picker.
### 2. Test Interactively
@@ -21,7 +22,7 @@ Load the `tmux-cli` skill, then use the `tmux-cli` tool. Install if needed: `uv
```bash
# Launch shell in test repo
pane=$(tmux-cli launch "zsh")
-tmux-cli send "cd target/wt-perf/picker-test" --pane=$pane
+tmux-cli send "cd /tmp/wt-picker-test" --pane=$pane
tmux-cli wait_idle --pane=$pane
# Run with debug logging
@@ -43,7 +44,7 @@ MCP terminals use pseudo-TTY, not real terminals. If tests pass in MCP but users
```typescript
// Create terminal and navigate to test repo
mcp__node-terminal__terminal_create({ sessionId: "test" })
-mcp__node-terminal__terminal_write({ sessionId: "test", input: "cd target/wt-perf/picker-test" })
+mcp__node-terminal__terminal_write({ sessionId: "test", input: "cd /tmp/wt-picker-test" })
mcp__node-terminal__terminal_send_key({ sessionId: "test", key: "enter" })
// Run with debug logging
diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rs
index ecc6f18e8..0b51ba24c 100644
--- a/src/commands/list/mod.rs
+++ b/src/commands/list/mod.rs
@@ -107,7 +107,7 @@
//! - Dominated by git command overhead, not Rust code
//! - Cold caches: ~150-300ms per worktree (typical repo, 500 commits, 100 files)
//! - Warm caches: ~20-50ms per worktree
-//! - Real-world: rust-lang/rust repo with 8 worktrees: ~400ms (warm caches)
+//! - Large-repository corpus (currently rust-lang/rust), 8 worktrees: ~400ms warm
//!
//! Bottlenecks:
//! 1. `git status --porcelain` - Slowest when index is cold or many files changed
diff --git a/src/testing/mod.rs b/src/testing/mod.rs
index 80d598419..725f7fae1 100644
--- a/src/testing/mod.rs
+++ b/src/testing/mod.rs
@@ -439,7 +439,7 @@ const GIT_ALLOWED_PROTOCOLS: &str = "file";
/// Restore git's default protocol set on a command built by
/// [`configure_git_cmd`], for a caller whose job is to fetch a fixture from
-/// upstream β€” the real-repo benchmark clone. Grep for this to enumerate
+/// upstream β€” the large-repository benchmark corpus. Grep for this to enumerate
/// everything that may reach the wire; tests are not among them.
pub fn allow_network_transports(cmd: &mut Command) {
cmd.env_remove("GIT_ALLOW_PROTOCOL");
diff --git a/tests/helpers/wt-perf/Cargo.toml b/tests/helpers/wt-perf/Cargo.toml
index 02fb05982..739885daf 100644
--- a/tests/helpers/wt-perf/Cargo.toml
+++ b/tests/helpers/wt-perf/Cargo.toml
@@ -15,6 +15,7 @@ description = "Performance testing and tracing tools for worktrunk"
# For repo setup
tempfile = "3.27"
dunce = "1"
+fs2 = "0.4.3"
# For CLI
clap = { version = "4.6", features = ["derive"] }
diff --git a/tests/helpers/wt-perf/src/lib.rs b/tests/helpers/wt-perf/src/lib.rs
index 82dedce06..6a115839a 100644
--- a/tests/helpers/wt-perf/src/lib.rs
+++ b/tests/helpers/wt-perf/src/lib.rs
@@ -9,10 +9,10 @@
//! # Library Usage
//!
//! ```rust,ignore
-//! use wt_perf::{RepoConfig, create_repo, invalidate_caches_auto};
+//! use wt_perf::{FixtureRecipe, invalidate_caches_auto};
//!
-//! // Create a test repo with 8 worktrees
-//! let fixture = create_repo(&RepoConfig::typical(8));
+//! // Create a typical repo with 8 total worktrees.
+//! let fixture = FixtureRecipe::Typical { total_worktrees: 8 }.create();
//!
//! // Invalidate caches for cold benchmark
//! invalidate_caches_auto(fixture.path());
@@ -20,14 +20,29 @@
//!
//! See `wt-perf --help` for CLI usage.
+use clap::Subcommand;
+use fs2::FileExt;
+use std::fs::{File, OpenOptions};
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
-use std::sync::OnceLock;
use tempfile::TempDir;
use worktrunk::testing::{allow_network_transports, configure_git_cmd, isolate_subprocess_env};
-/// Lazy-initialized rust repo path.
-static RUST_REPO: OnceLock<PathBuf> = OnceLock::new();
+mod large_repository_fixture {
+ include!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../../../benches/large-repository-fixture"
+ ));
+}
+use large_repository_fixture::{
+ CORPUS as LARGE_REPOSITORY_CORPUS, REVISION as LARGE_REPOSITORY_REVISION,
+};
+/// Worktrees in the canonical read-only large-repository fixture, including
+/// the primary worktree.
+const LARGE_REPOSITORY_TOTAL_WORKTREES: usize = 8;
+/// Branches in the canonical read-only large-repository fixture, spread over
+/// the most recent 5,000 commits.
+const LARGE_REPOSITORY_HISTORY_SPREAD_BRANCHES: usize = 50;
/// An owned temporary benchmark fixture.
///
@@ -50,6 +65,29 @@ impl FixtureRepo {
Self { root, repo }
}
+ /// Create a fixture in `parent`, keeping large temporary fixtures on the
+ /// same volume as the shared source cache.
+ fn create_in(parent: &Path, build: impl FnOnce(&Path)) -> Self {
+ std::fs::create_dir_all(parent).unwrap_or_else(|error| {
+ panic!(
+ "failed to create fixture directory {}: {error}",
+ parent.display()
+ )
+ });
+ let root = tempfile::Builder::new()
+ .prefix("fixture-")
+ .tempdir_in(parent)
+ .unwrap_or_else(|error| {
+ panic!(
+ "failed to create temporary fixture in {}: {error}",
+ parent.display()
+ )
+ });
+ let repo = root.path().join("repo");
+ build(&repo);
+ Self { root, repo }
+ }
+
/// Path to the fixture's primary worktree.
pub fn path(&self) -> &Path {
&self.repo
@@ -75,131 +113,206 @@ pub fn linked_worktree_path(repo_path: &Path, branch: &str) -> PathBuf {
.join(format!("{repo_name}.{branch}"))
}
-/// Configuration for creating a benchmark repository.
+/// Low-level parameters for the flat synthetic repository builder.
+///
+/// Benchmark callers name a [`FixtureRecipe`]. Keeping this type private
+/// prevents arbitrary parameter combinations from becoming an accidental
+/// second fixture catalog.
#[derive(Clone, Debug)]
-pub struct RepoConfig {
+struct FlatRepoConfig {
/// Number of commits on main branch
- pub commits_on_main: usize,
+ commits_on_main: usize,
/// Number of files in the repo
- pub files: usize,
+ files: usize,
/// Number of branches (without worktrees)
- pub branches: usize,
+ branchless_branches: usize,
/// Commits per branch
- pub commits_per_branch: usize,
+ commits_per_branch: usize,
/// Number of worktrees (including main)
- pub worktrees: usize,
+ total_worktrees: usize,
/// Commits ahead of main per worktree
- pub worktree_commits_ahead: usize,
+ worktree_commits_ahead: usize,
/// Uncommitted files per worktree
- pub worktree_uncommitted_files: usize,
+ worktree_uncommitted_files: usize,
}
-impl RepoConfig {
+impl FlatRepoConfig {
/// Typical repo with worktrees (500 commits, 100 files).
///
/// Good for skeleton rendering and general worktree benchmarks.
- pub const fn typical(worktrees: usize) -> Self {
+ const fn typical(total_worktrees: usize) -> Self {
Self {
commits_on_main: 500,
files: 100,
- branches: 0,
+ branchless_branches: 0,
commits_per_branch: 0,
- worktrees,
+ total_worktrees,
worktree_commits_ahead: 10,
worktree_uncommitted_files: 3,
}
}
/// Branch-focused config (minimal history, many branches).
- pub const fn branches(count: usize, commits_per_branch: usize) -> Self {
+ const fn minimal(
+ branchless_branches: usize,
+ linked_worktrees: usize,
+ commits_per_branch: usize,
+ ) -> Self {
Self {
commits_on_main: 1,
files: 1,
- branches: count,
+ branchless_branches,
commits_per_branch,
- worktrees: 0,
+ total_worktrees: linked_worktrees + 1,
worktree_commits_ahead: 0,
worktree_uncommitted_files: 0,
}
}
/// Many divergent branches (GH #461 scenario: 200 branches Γ— 20 commits).
- pub const fn many_divergent_branches() -> Self {
+ const fn synthetic_divergence() -> Self {
Self {
commits_on_main: 100,
files: 50,
- branches: 200,
+ branchless_branches: 200,
commits_per_branch: 20,
- worktrees: 0,
+ total_worktrees: 1,
worktree_commits_ahead: 0,
worktree_uncommitted_files: 0,
}
}
-
- /// Config for testing `wt switch` interactive picker (6 worktrees with varying commits).
- pub const fn picker_test() -> Self {
- Self {
- commits_on_main: 3,
- files: 3,
- branches: 2, // feature-000, feature-001 (no worktree)
- commits_per_branch: 0,
- worktrees: 6,
- worktree_commits_ahead: 15, // feature worktree has many commits
- worktree_uncommitted_files: 1,
- }
- }
}
-/// A parsed `wt-perf setup` config string.
+/// The benchmark fixture catalog.
///
-/// Most configs map onto the flat [`RepoConfig`] (every worktree/branch
-/// identical); the composite fixtures build varied states instead:
-/// `mixed-W-B` via `create_mixed_repo_at`, `prune-M-U` via
-/// [`create_prune_repo_at`]. (`prune-real[-M-U]` is not a `SetupConfig`:
-/// it is managed under `target/wt-perf/bench-repos/` and takes no path β€” see
-/// [`ensure_prune_real_repo`].)
-pub enum SetupConfig {
- Flat(RepoConfig),
+/// Variants are sparse, named repository states rather than combinations of
+/// independent base, shape, and storage axes. Large-corpus recipes reuse the
+/// same pinned source while every mutable fixture remains caller-owned.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Subcommand)]
+pub enum FixtureRecipe {
+ /// Standard synthetic history, files, and feature worktrees.
+ Typical {
+ /// Total worktrees, including the primary worktree.
+ #[arg(value_parser = positive_usize)]
+ total_worktrees: usize,
+ },
+ /// Minimal history and files with configurable branch/worktree populations.
+ Minimal {
+ /// Branches without linked worktrees.
+ branchless_branches: usize,
+ /// Linked worktrees, excluding the primary worktree.
+ linked_worktrees: usize,
+ },
+ /// Fixed deep-divergence branch stress.
+ SyntheticDivergence,
+ /// Pinned large corpus with worktrees and branches spread across history.
+ LargeRepository,
+ /// Varied branch and worktree state rotation.
Mixed {
- worktrees: usize,
- branches: usize,
- remote_refs: usize,
+ /// Linked worktrees, excluding the primary worktree.
+ linked_worktrees: usize,
+ /// Branches without linked worktrees.
+ branchless_branches: usize,
+ /// Additional remote-tracking refs.
+ #[arg(default_value_t = 0)]
+ remote_tracking_refs: usize,
},
+ /// Prune candidates and the unintegrated scan backdrop.
Prune {
- merged: usize,
- unmerged: usize,
+ /// Squash-merged worktree/branch pairs.
+ candidate_pairs: usize,
+ /// Unintegrated worktree/branch pairs.
+ backdrop_pairs: usize,
+ },
+ /// Pinned large corpus with prune candidates and an unintegrated backdrop.
+ LargeRepositoryPrune {
+ /// Squash-merged worktree/branch pairs.
+ candidate_pairs: usize,
+ /// Unintegrated worktree/branch pairs.
+ backdrop_pairs: usize,
},
}
-impl SetupConfig {
- /// Create the repo at `base_path`; returns `(worktrees, branches)`.
- pub fn create_at(&self, base_path: &Path) -> (usize, usize) {
+fn positive_usize(value: &str) -> Result<usize, String> {
+ let value = value
+ .parse::<usize>()
+ .map_err(|_| "expected a positive integer".to_string())?;
+ (value >= 1)
+ .then_some(value)
+ .ok_or_else(|| "expected a positive integer".to_string())
+}
+
+impl FixtureRecipe {
+ /// Build an owned ephemeral fixture.
+ pub fn create(self) -> FixtureRepo {
+ let build = |repo: &Path| self.create_at(repo);
+ if matches!(self, Self::LargeRepositoryPrune { .. }) {
+ FixtureRepo::create_in(&large_repository_cache_dir().join("runs"), build)
+ } else {
+ FixtureRepo::create(build)
+ }
+ }
+
+ /// Build an ephemeral fixture at a caller-chosen primary-worktree path.
+ pub fn create_at(self, base_path: &Path) {
match self {
- SetupConfig::Flat(cfg) => {
- create_repo_at(cfg, base_path);
- (cfg.worktrees, cfg.branches)
+ Self::Typical { total_worktrees } => {
+ assert!(total_worktrees >= 1, "a fixture has a primary worktree");
+ build_flat_repo_at(&FlatRepoConfig::typical(total_worktrees), base_path);
+ }
+ Self::Minimal {
+ branchless_branches,
+ linked_worktrees,
+ } => {
+ build_flat_repo_at(
+ &FlatRepoConfig::minimal(branchless_branches, linked_worktrees, 0),
+ base_path,
+ );
+ }
+ Self::SyntheticDivergence => {
+ let config = FlatRepoConfig::synthetic_divergence();
+ build_flat_repo_at(&config, base_path);
+ }
+ Self::LargeRepository => {
+ clone_large_repository_at(base_path);
+ add_history_spread_branches(base_path, LARGE_REPOSITORY_HISTORY_SPREAD_BRANCHES);
+ add_typical_linked_worktrees(base_path, LARGE_REPOSITORY_TOTAL_WORKTREES - 1);
}
- SetupConfig::Mixed {
- worktrees,
- branches,
- remote_refs,
+ Self::Mixed {
+ linked_worktrees,
+ branchless_branches,
+ remote_tracking_refs,
} => {
- create_mixed_repo_at(*worktrees, *branches, *remote_refs, base_path);
- (*worktrees, *branches)
+ build_mixed_repo_at(
+ linked_worktrees,
+ branchless_branches,
+ remote_tracking_refs,
+ base_path,
+ );
+ }
+ Self::Prune {
+ candidate_pairs,
+ backdrop_pairs,
+ } => {
+ build_prune_repo_at(candidate_pairs, backdrop_pairs, base_path);
}
- SetupConfig::Prune { merged, unmerged } => {
- create_prune_repo_at(*merged, *unmerged, base_path);
- (merged + unmerged + 1, merged + unmerged)
+ Self::LargeRepositoryPrune {
+ candidate_pairs,
+ backdrop_pairs,
+ } => {
+ clone_large_repository_at(base_path);
+ add_prune_populations(base_path, candidate_pairs, backdrop_pairs);
}
}
}
}
-/// Parse a `<prefix>A-B` config string (e.g. `mixed-4-8`) into its two counts.
-pub fn parse_pair(config: &str, prefix: &str) -> Option<(usize, usize)> {
- let rest = config.strip_prefix(prefix)?;
- let (a, b) = rest.split_once('-')?;
- Some((a.parse().ok()?, b.parse().ok()?))
+/// Add the standard linked-worktree population to an existing typical fixture.
+///
+/// Destructive benchmarks use this after committing scenario-specific
+/// configuration on the primary worktree but before recording a candidate.
+pub fn add_typical_linked_worktrees(repo_path: &Path, linked_worktrees: usize) {
+ add_flat_worktrees(&FlatRepoConfig::typical(linked_worktrees + 1), repo_path);
}
/// Build a `git` command isolated from host context, with the host's
@@ -219,8 +332,8 @@ fn git_command() -> Command {
pub enum CacheState {
/// Persistent caches stay hot across iterations (steady-state re-run).
Warm,
- /// [`invalidate_caches_auto`] per iteration: git's own caches (indexes,
- /// commit graph) plus worktrunk's β€” a first run against fresh state.
+ /// [`invalidate_caches_auto`] per iteration: git's commit graph plus
+ /// worktrunk's caches β€” a first run against fresh, equivalent repo state.
Cold,
/// [`invalidate_probe_caches`] per iteration: only `.git/wt/cache/` β€”
/// the first scan after new commits land, git's state staying warm.
@@ -241,6 +354,14 @@ impl CacheState {
}
}
+/// Criterion profile for the standard subprocess benchmark cadence.
+pub fn standard_benchmark_profile() -> criterion::Criterion {
+ criterion::Criterion::default()
+ .sample_size(30)
+ .measurement_time(std::time::Duration::from_secs(15))
+ .warm_up_time(std::time::Duration::from_secs(3))
+}
+
/// Build a `wt` command with the benchmark subprocess environment isolated
/// from the developer's git, shell, and worktrunk configuration.
pub fn wt_command(binary: &Path, repo_path: &Path, user_config: Option<&Path>) -> Command {
@@ -389,20 +510,12 @@ fn git_stdout(path: &Path, args: &[&str], index_file: &Path) -> String {
)
}
-/// Create a test repository from config.
-///
-/// Returns an owned fixture whose primary worktree is available through
-/// [`FixtureRepo::path`].
-pub fn create_repo(config: &RepoConfig) -> FixtureRepo {
- FixtureRepo::create(|repo| create_repo_at(config, repo))
-}
-
/// Create a test repository at a specific path.
///
/// Uses worktrunk naming convention:
/// - Main worktree: `base_path`
/// - Feature worktrees: `base_path.feature-wt-N` (siblings in parent directory)
-pub fn create_repo_at(config: &RepoConfig, base_path: &Path) {
+fn build_flat_repo_at(config: &FlatRepoConfig, base_path: &Path) {
let repo_path = base_path.to_path_buf();
init_bench_repo(&repo_path);
@@ -442,7 +555,7 @@ pub fn create_repo_at(config: &RepoConfig, base_path: &Path) {
}
// Create branches (without worktrees)
- for i in 0..config.branches {
+ for i in 0..config.branchless_branches {
let branch_name = format!("feature-{i:03}");
run_git(&repo_path, &["checkout", "-b", &branch_name, "main"]);
@@ -464,11 +577,11 @@ pub fn create_repo_at(config: &RepoConfig, base_path: &Path) {
}
}
- if config.branches > 0 {
+ if config.branchless_branches > 0 {
run_git(&repo_path, &["checkout", "main"]);
}
- add_worktrees(config, &repo_path);
+ add_flat_worktrees(config, &repo_path);
// Set up fake remote for default branch detection
setup_fake_remote(&repo_path);
@@ -484,11 +597,11 @@ pub fn create_repo_at(config: &RepoConfig, base_path: &Path) {
/// Add worktrees to an existing repo using worktrunk naming convention.
///
-/// Creates `config.worktrees - 1` linked worktrees as siblings of `repo_path`
+/// Creates `config.total_worktrees - 1` linked worktrees as siblings of `repo_path`
/// (e.g., `repo.feature-wt-1`), each with diverging commits and uncommitted files
/// controlled by `config.worktree_commits_ahead` and `config.worktree_uncommitted_files`.
-pub fn add_worktrees(config: &RepoConfig, repo_path: &Path) {
- for wt_num in 1..config.worktrees {
+fn add_flat_worktrees(config: &FlatRepoConfig, repo_path: &Path) {
+ for wt_num in 1..config.total_worktrees {
let branch = format!("feature-wt-{wt_num}");
let wt_path = linked_worktree_path(repo_path, &branch);
@@ -537,7 +650,7 @@ pub fn add_worktrees(config: &RepoConfig, repo_path: &Path) {
/// than all pointing at `HEAD`, which would leave `%(committerdate)` re-reading
/// one object and understate the scan. It does not reach one object per ref:
/// the round-robin can only spread over the history it has, so at
-/// `create_mixed_repo`'s 200 commits a four-digit ref count lands ~7 refs on
+/// the mixed recipe's 200 commits, a four-digit ref count lands ~7 refs on
/// each of ~200 distinct commits. Git parses a given object once and reuses it
/// for the rest of the `for-each-ref`, so the scan pays ~200 parses plus a
/// cheap iteration hit per ref, where a real long-lived clone β€” whose remote
@@ -560,7 +673,7 @@ pub fn add_worktrees(config: &RepoConfig, repo_path: &Path) {
/// One `update-ref --stdin` fork writes the whole batch; the per-ref
/// alternative costs a fork each and dominates fixture build time at the
/// four-digit counts this exists to model.
-fn add_remote_refs(count: usize, repo_path: &Path) {
+fn add_remote_tracking_refs(count: usize, repo_path: &Path) {
if count == 0 {
return;
}
@@ -618,7 +731,6 @@ pub fn setup_fake_remote(repo_path: &Path) {
/// of which worktree of a repo `repo_path` names.
///
/// Clears:
-/// - Git's index (main + linked worktrees) β€” fsmonitor/stat warmup
/// - Commit graph (`objects/info/commit-graph*`)
/// - All of `.git/wt/cache/` β€” worktrunk's persistent SHA-keyed caches
/// (merge-tree-conflicts, merge-add-probe, is-ancestor, has-added-changes,
@@ -631,24 +743,21 @@ pub fn setup_fake_remote(repo_path: &Path) {
/// `worktrunk.hints.*`, `worktrunk.state.<branch>.*`, `.git/wt/logs/`,
/// `.git/wt/trash/`. These don't affect read-path performance, and benches
/// may rely on them (e.g., branch markers set during setup).
+///
+/// Worktree indexes are deliberately preserved. An index carries staged state,
+/// not just stat/fsmonitor acceleration; removing it makes git report every
+/// tracked file as staged for deletion and changes which candidates commands
+/// see. A benchmark's cold and warm variants must differ only in cache state.
pub fn invalidate_caches_auto(repo_path: &Path) {
let Some(git_dir) = resolve_git_common_dir(repo_path) else {
return;
};
- // Remove main index + every linked worktree's index.
- let _ = std::fs::remove_file(git_dir.join("index"));
- if let Ok(entries) = std::fs::read_dir(git_dir.join("worktrees")) {
- for entry in entries.flatten() {
- let _ = std::fs::remove_file(entry.path().join("index"));
- }
- }
-
// Commit graph: legacy single-file plus chained-graph dir.
- let _ = std::fs::remove_file(git_dir.join("objects/info/commit-graph"));
- let _ = std::fs::remove_dir_all(git_dir.join("objects/info/commit-graphs"));
+ remove_file_if_exists(&git_dir.join("objects/info/commit-graph"));
+ remove_dir_if_exists(&git_dir.join("objects/info/commit-graphs"));
- // Note: `packed-refs` is intentionally NOT removed. After `create_repo_at`
+ // Note: `packed-refs` is intentionally NOT removed. After `build_flat_repo_at`
// runs an explicit `git gc`, every loose ref under `refs/heads/`,
// `refs/remotes/`, etc. is packed into `packed-refs` and the loose files
// are pruned. Deleting `packed-refs` in that state leaves the repo with
@@ -666,20 +775,19 @@ pub fn invalidate_caches_auto(repo_path: &Path) {
// out. Exit 5 = key absent (harmless); anything else is a real
// failure and we want it loud, since the bench's cold-cache
// invariant depends on this succeeding.
- let result = git_command()
+ let output = git_command()
.args(["config", "--unset", "worktrunk.default-branch"])
.current_dir(repo_path)
- .output();
- match result {
- Ok(o) if o.status.success() => {}
- Ok(o) if o.status.code() == Some(5) => {}
- Ok(o) => eprintln!(
- "wt-perf invalidate: `git config --unset worktrunk.default-branch` failed (exit {:?}): {}",
- o.status.code(),
- String::from_utf8_lossy(&o.stderr).trim()
- ),
- Err(e) => eprintln!("wt-perf invalidate: failed to spawn git: {e}"),
- }
+ .output()
+ .unwrap_or_else(|error| {
+ panic!("failed to run `git config --unset worktrunk.default-branch`: {error}")
+ });
+ assert!(
+ output.status.success() || output.status.code() == Some(5),
+ "`git config --unset worktrunk.default-branch` failed (exit {:?}): {}",
+ output.status.code(),
+ String::from_utf8_lossy(&output.stderr).trim()
+ );
}
/// Invalidate only worktrunk's persistent probe caches (`.git/wt/cache/`).
@@ -688,45 +796,35 @@ pub fn invalidate_caches_auto(repo_path: &Path) {
/// branch, every sha_cache entry keyed on the old tips misses, while git's
/// own state stays warm β€” indexes keep their stat data, and the commit graph
/// and `worktrunk.default-branch` config entry survive a fetch. This is the
-/// "first `wt step prune` after fetching main" shape, and it is safe against
-/// clean-worktree gates: deleting an *index* (as [`invalidate_caches_auto`]
-/// does) doesn't model a cold cache β€” git treats a missing index as empty, so
-/// `git status` reports every tracked file as a staged deletion, a different
-/// repo state that flips removability checks and silently drops worktree
-/// candidates from a prune scan.
+/// "first `wt step prune` after fetching main" shape. Like
+/// [`invalidate_caches_auto`], it preserves worktree indexes so clean-worktree
+/// gates see the same repository state as a warm run.
pub fn invalidate_probe_caches(repo_path: &Path) {
let Some(git_dir) = resolve_git_common_dir(repo_path) else {
return;
};
- let _ = std::fs::remove_dir_all(git_dir.join("wt/cache"));
+ remove_dir_if_exists(&git_dir.join("wt/cache"));
}
-/// Rebuild every worktree's index via `git reset -q`.
-///
-/// Used by [`ensure_prune_real_repo`] to heal a fixture whose indexes were
-/// deleted by a stray `wt-perf invalidate` / `timeline --cold` (a missing
-/// index reads as all-tracked-files-deleted and flips prune's clean-worktree
-/// gate β€” see [`invalidate_probe_caches`]). `git reset --mixed` discards
-/// staged-but-uncommitted index state, so this is safe only on fixtures
-/// whose dirt is untracked files.
-fn restore_worktree_indexes(repo_path: &Path) {
- let output = git_command()
- .args(["worktree", "list", "--porcelain"])
- .current_dir(repo_path)
- .output()
- .unwrap();
- assert!(output.status.success(), "git worktree list failed");
- let stdout = String::from_utf8_lossy(&output.stdout);
- // Parallel: each reset rebuilds one worktree's index from its own HEAD,
- // fully independent of the others. On the rust-scale fixture a rebuild
- // is ~2.5 s per worktree β€” serially that would dominate the repair.
- std::thread::scope(|s| {
- for line in stdout.lines() {
- if let Some(path) = line.strip_prefix("worktree ") {
- s.spawn(move || run_git(Path::new(path), &["reset", "-q"]));
- }
- }
- });
+/// Remove a cache file, treating only absence as an already-cold cache.
+fn remove_file_if_exists(path: &Path) {
+ match std::fs::remove_file(path) {
+ Ok(()) => {}
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
+ Err(error) => panic!("failed to remove cache file {}: {error}", path.display()),
+ }
+}
+
+/// Remove a cache directory, treating only absence as an already-cold cache.
+fn remove_dir_if_exists(path: &Path) {
+ match std::fs::remove_dir_all(path) {
+ Ok(()) => {}
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
+ Err(error) => panic!(
+ "failed to remove cache directory {}: {error}",
+ path.display()
+ ),
+ }
}
/// Resolve git's common directory for `repo_path` from the filesystem.
@@ -773,7 +871,7 @@ fn resolve_git_common_dir(repo_path: &Path) -> Option<PathBuf> {
/// Living under `target/` means `cargo clean` reaps every fixture and each git
/// worktree keeps its own copy (worktrees don't share `target/`). That is cheap
/// for the synthetic `setup` fixtures β€” rebuilt in seconds β€” but a deliberate
-/// cost for the ~15 GiB rust clone under `bench-repos/`, which then re-clones
+/// cost for the ~15 GiB large-repository fixture under `bench-repos/`, which then re-clones
/// per worktree and after every `cargo clean`. Relocate it with cargo's own
/// `CARGO_TARGET_DIR` if that cost bites.
pub fn wt_perf_fixture_dir() -> PathBuf {
@@ -819,81 +917,173 @@ fn target_dir_from_exe(exe: &Path) -> Option<PathBuf> {
.map(Path::to_path_buf)
}
-/// The shared store for real, cloned upstream fixtures (rust-lang/rust and the
-/// prune fixtures derived from it): `<workspace>/target/wt-perf/bench-repos`.
-fn bench_repos_dir() -> PathBuf {
- wt_perf_fixture_dir().join("bench-repos")
+fn large_repository_cache_dir() -> PathBuf {
+ wt_perf_fixture_dir()
+ .join("bench-repos")
+ .join("large-repository")
+}
+
+fn acquire_exclusive_lock(path: &Path) -> File {
+ std::fs::create_dir_all(path.parent().unwrap()).unwrap_or_else(|error| {
+ panic!(
+ "failed to create fixture lock directory {}: {error}",
+ path.parent().unwrap().display()
+ )
+ });
+ let file = OpenOptions::new()
+ .create(true)
+ .truncate(false)
+ .write(true)
+ .open(path)
+ .unwrap_or_else(|error| panic!("failed to open fixture lock {}: {error}", path.display()));
+ file.lock_exclusive()
+ .unwrap_or_else(|error| panic!("failed to lock fixture {}: {error}", path.display()));
+ file
+}
+
+fn path_exists(path: &Path) -> bool {
+ path.try_exists()
+ .unwrap_or_else(|error| panic!("failed to inspect {}: {error}", path.display()))
}
-/// Get or clone the rust-lang/rust repository for real-world benchmarks.
+fn repository_head(repo: &Path) -> Option<String> {
+ let output = git_command()
+ .args(["rev-parse", "--verify", "HEAD^{commit}"])
+ .current_dir(repo)
+ .output()
+ .unwrap_or_else(|error| {
+ panic!(
+ "failed to inspect repository HEAD at {}: {error}",
+ repo.display()
+ )
+ });
+ output
+ .status
+ .success()
+ .then(|| String::from_utf8_lossy(&output.stdout).trim().to_string())
+}
+
+fn repository_is_on_main(repo: &Path) -> bool {
+ let output = git_command()
+ .args(["symbolic-ref", "--quiet", "--short", "HEAD"])
+ .current_dir(repo)
+ .output()
+ .unwrap_or_else(|error| {
+ panic!(
+ "failed to inspect repository branch at {}: {error}",
+ repo.display()
+ )
+ });
+ output.status.success() && String::from_utf8_lossy(&output.stdout).trim() == "main"
+}
+
+fn large_repository_source_matches(repo: &Path) -> bool {
+ path_exists(repo)
+ && repository_head(repo).as_deref() == Some(LARGE_REPOSITORY_REVISION)
+ && repository_is_on_main(repo)
+ && run_git_ok(repo, &["fsck", "--connectivity-only", "--no-dangling"])
+}
+
+/// Get or build the immutable source for large-repository benchmarks.
///
-/// The repo is cached at `target/wt-perf/bench-repos/rust` and reused across runs.
-fn ensure_rust_repo() -> PathBuf {
- RUST_REPO
- .get_or_init(|| {
- let cache_dir = bench_repos_dir();
- let rust_repo = cache_dir.join("rust");
-
- if rust_repo.exists() {
- let output = git_command()
- .args(["rev-parse", "HEAD"])
- .current_dir(&rust_repo)
- .output();
-
- if output.is_ok_and(|o| o.status.success()) {
- eprintln!("Using cached rust repo at {}", rust_repo.display());
- return rust_repo;
- }
- eprintln!("Cached rust repo corrupted, re-cloning...");
- std::fs::remove_dir_all(&rust_repo).unwrap();
- }
+/// The revision is part of the cache path. Construction happens in a temporary
+/// sibling and is atomically renamed into place after validation, so an
+/// interrupted clone never looks like a usable cache entry.
+fn ensure_large_repository_source() -> PathBuf {
+ let cache_dir = large_repository_cache_dir();
+ let source = cache_dir.join(format!("source-{LARGE_REPOSITORY_REVISION}"));
+ let staged_source = cache_dir.join(format!("source-{LARGE_REPOSITORY_REVISION}.building"));
+ let _build_lock =
+ acquire_exclusive_lock(&cache_dir.join(format!("source-{LARGE_REPOSITORY_REVISION}.lock")));
+ if path_exists(&staged_source) {
+ remove_dir_if_exists(&staged_source);
+ }
- std::fs::create_dir_all(&cache_dir).unwrap();
- eprintln!("Cloning rust-lang/rust (this will take several minutes)...");
-
- let mut clone = git_command();
- allow_network_transports(&mut clone);
- let clone_output = clone
- .args([
- "clone",
- "https://github.com/rust-lang/rust.git",
- rust_repo.to_str().unwrap(),
- ])
- .output()
- .unwrap();
+ if large_repository_source_matches(&source) {
+ eprintln!(
+ "Using cached large-repository source at {}",
+ source.display()
+ );
+ return source;
+ }
+ if path_exists(&source) {
+ eprintln!("Cached large-repository source is invalid; rebuilding");
+ remove_dir_if_exists(&source);
+ }
- assert!(clone_output.status.success(), "Failed to clone rust repo");
- eprintln!("Rust repo cloned successfully");
- rust_repo
- })
- .clone()
+ let url = format!("https://github.com/{LARGE_REPOSITORY_CORPUS}.git");
+ eprintln!(
+ "Cloning {} at {} (this will take several minutes)...",
+ LARGE_REPOSITORY_CORPUS, LARGE_REPOSITORY_REVISION
+ );
+ let mut clone = git_command();
+ allow_network_transports(&mut clone);
+ let output = clone
+ .args(["clone", "--no-checkout", &url])
+ .arg(&staged_source)
+ .output()
+ .unwrap_or_else(|error| panic!("failed to spawn large-repository clone: {error}"));
+ assert!(
+ output.status.success(),
+ "failed to clone {}:\n{}",
+ LARGE_REPOSITORY_CORPUS,
+ String::from_utf8_lossy(&output.stderr)
+ );
+ run_git(
+ &staged_source,
+ &["checkout", "--detach", LARGE_REPOSITORY_REVISION],
+ );
+ run_git(
+ &staged_source,
+ &["branch", "-f", "main", LARGE_REPOSITORY_REVISION],
+ );
+ run_git(&staged_source, &["checkout", "main"]);
+ assert!(
+ large_repository_source_matches(&staged_source),
+ "large-repository source failed validation after checkout"
+ );
+ std::fs::rename(&staged_source, &source).unwrap_or_else(|error| {
+ panic!(
+ "failed to publish large-repository source {}: {error}",
+ source.display()
+ )
+ });
+ eprintln!("Large-repository source cloned successfully");
+ source
}
-/// Local-clone the cached rust repo (`ensure_rust_repo`) to `dest` and
-/// configure a git user for commits.
-fn clone_rust_repo_at(dest: &Path) {
- let rust_repo = ensure_rust_repo();
+/// Local-clone the pinned large-repository source to `dest` and configure a
+/// git user for fixture commits.
+fn clone_large_repository_at(dest: &Path) {
+ let source = ensure_large_repository_source();
let clone_output = git_command()
.args([
"clone",
"--local",
- rust_repo.to_str().unwrap(),
+ "--single-branch",
+ "--branch",
+ "main",
+ source.to_str().unwrap(),
dest.to_str().unwrap(),
])
.output()
.unwrap();
assert!(
clone_output.status.success(),
- "Failed to local-clone rust repo: {}",
+ "Failed to local-clone large-repository source: {}",
String::from_utf8_lossy(&clone_output.stderr)
);
run_git(dest, &["config", "user.name", "Benchmark"]);
run_git(dest, &["config", "user.email", "[email protected]"]);
-}
-
-/// Clone rust-lang/rust into an owned temporary benchmark fixture.
-pub fn clone_rust_repo() -> FixtureRepo {
- FixtureRepo::create(clone_rust_repo_at)
+ assert_eq!(
+ repository_head(dest).as_deref(),
+ Some(LARGE_REPOSITORY_REVISION),
+ "large-repository clone did not retain the pinned revision"
+ );
+ assert!(
+ repository_is_on_main(dest),
+ "large-repository clone must check out the pinned main branch"
+ );
}
/// Sample up to `count` commit SHAs evenly spread across the last 5000
@@ -986,15 +1176,20 @@ fn add_branch_with_commits(repo_path: &Path, branch: &str, fork: &str, commits:
/// `feature-NNN` branches pointing at them. None carries its own commits, so
/// every branch is an ancestor of the tip β€” behind it, except `feature-000`:
/// the newest sample is the tip itself, so that one sits exactly on it.
-pub fn add_history_spread_branches(repo_path: &Path, count: usize) {
- for (i, commit) in history_spread_shas(repo_path, count).iter().enumerate() {
+fn add_history_spread_branches(repo_path: &Path, branchless_branches: usize) {
+ let commits = history_spread_shas(repo_path, branchless_branches);
+ assert_eq!(
+ commits.len(),
+ branchless_branches,
+ "history-spread fixture needs at least {branchless_branches} commits"
+ );
+ for (i, commit) in commits.iter().enumerate() {
add_branch_with_commits(repo_path, &format!("feature-{i:03}"), commit, 0);
}
}
-/// Add `worktrees` two-sided-diverged linked worktrees (`feature-wt-N`) and
-/// `branches` two-sided-diverged orphan branches (`feature-NNN`) to an
-/// existing repo.
+/// Add two-sided-diverged linked worktrees (`feature-wt-N`) and branchless
+/// branches (`feature-NNN`) to an existing repo.
///
/// Each forks at a `history_spread_shas` point and carries its own commits on
/// top. That is the shape of real long-lived feature work: `git merge-base`
@@ -1014,15 +1209,15 @@ pub fn add_history_spread_branches(repo_path: &Path, count: usize) {
///
/// The populations are sized independently because their costs differ wildly
/// on large repos: an orphan branch is a few commits' worth of objects, while
-/// a linked worktree materializes a full working tree (~1 GiB on
-/// rust-lang/rust) and pays a checkout.
-fn add_diverged_backdrop(repo_path: &Path, worktrees: usize, branches: usize) {
- let forks = history_spread_shas(repo_path, worktrees.max(branches).max(1));
+/// a linked worktree materializes a full working tree (hundreds of MiB in the
+/// pinned corpus) and pays a checkout.
+fn add_diverged_backdrop(repo_path: &Path, linked_worktrees: usize, branchless_branches: usize) {
+ let forks = history_spread_shas(repo_path, linked_worktrees.max(branchless_branches).max(1));
// Each orphan branch forks at a spread point and carries 3 commits of its
// own, so the default branch has advanced past it on one side while it
// advanced on the other.
- for i in 0..branches {
+ for i in 0..branchless_branches {
add_branch_with_commits(
repo_path,
&format!("feature-{i:03}"),
@@ -1031,7 +1226,7 @@ fn add_diverged_backdrop(repo_path: &Path, worktrees: usize, branches: usize) {
);
}
- for i in 0..worktrees {
+ for i in 0..linked_worktrees {
let wt_branch = format!("feature-wt-{i}");
let wt_path = linked_worktree_path(repo_path, &wt_branch);
run_git(
@@ -1078,11 +1273,10 @@ fn append_line(path: &Path, rel: &str, line: &str) {
std::fs::write(&file, content).unwrap();
}
-/// Create a repo with `worktrees` linked worktrees AND `branches` branchless
-/// branches, each in a deterministic rotation of states, for the combined
-/// full-surface `wt list` benchmark (`full` in `benches/list.rs`).
+/// Create a repo with linked worktrees, branchless branches, and optional
+/// remote-tracking refs for the `full` list and shell-completion benchmarks.
///
-/// Unlike [`RepoConfig`] (every worktree/branch identical), this exercises the
+/// Unlike the flat recipes (every worktree/branch identical), this exercises the
/// full spread of `wt list` gates and tasks at once β€” clean vs dirty working
/// trees, merged vs ahead vs diverged branches, *and* divergence spread across
/// history depth β€” the realistic shape of "a huge number of worktrees &
@@ -1107,19 +1301,17 @@ fn append_line(path: &Path, rel: &str, line: &str) {
/// 2. diverged: a short own-commit chain forked from an older checkpoint
/// while base advanced (deep two-sided divergence)
/// 3. identical to the base tip (trees match β€” squash-merge shape)
-pub fn create_mixed_repo(worktrees: usize, branches: usize, remote_refs: usize) -> FixtureRepo {
- FixtureRepo::create(|repo| create_mixed_repo_at(worktrees, branches, remote_refs, repo))
-}
-
-/// [`create_mixed_repo`] at a caller-chosen path (used by `wt-perf setup
-/// mixed-W-B`). The main worktree is created at `repo`; linked worktrees are
-/// siblings.
-fn create_mixed_repo_at(worktrees: usize, branches: usize, remote_refs: usize, repo: &Path) {
+fn build_mixed_repo_at(
+ linked_worktrees: usize,
+ branchless_branches: usize,
+ remote_tracking_refs: usize,
+ repo: &Path,
+) {
const FILES: usize = 50;
// Deep enough that fork points spread across history give the
// `%(ahead-behind)` walk real commits to traverse (GH #461 shape), while
// staying far cheaper to build than the dedicated `divergent` stress
- // (`RepoConfig::many_divergent_branches`, 200 branches Γ— 20 commits).
+ // (`FixtureRecipe::SyntheticDivergence`, 200 branches Γ— 20 commits).
const BASE_COMMITS: usize = 200;
// Record a checkpoint every few commits so behind/diverged branches fork
// at many distinct depths rather than a handful of fixed points.
@@ -1156,7 +1348,7 @@ fn create_mixed_repo_at(worktrees: usize, branches: usize, remote_refs: usize, r
}
let base_tip = head_sha(&repo);
// `checkpoints[0]` is the oldest (initial commit); the last is near the
- // tip. Index `i` of `branches` maps linearly across them, so behind/
+ // tip. Index `i` of the branch population maps linearly across them, so behind/
// diverged branches fork at points fanned across history depth rather than
// a few repeated checkpoints.
let deepest = checkpoints.len() - 1;
@@ -1165,10 +1357,10 @@ fn create_mixed_repo_at(worktrees: usize, branches: usize, remote_refs: usize, r
// just a (fork point, own-commit count) pair β€” see
// `add_branch_with_commits`, which builds every one of them with plumbing,
// so nothing checks out and the main worktree is untouched throughout.
- for i in 0..branches {
+ for i in 0..branchless_branches {
let name = format!("br-{i:04}");
- // `branches >= 1` inside this loop, so the divisor is never zero.
- let checkpoint = checkpoints[i * deepest / branches].as_str();
+ // The count is at least one inside this loop, so the divisor is nonzero.
+ let checkpoint = checkpoints[i * deepest / branchless_branches].as_str();
let (fork, commits) = match i % 4 {
0 => (checkpoint, 0), // behind
1 => (base_tip.as_str(), 1 + i % 3), // ahead
@@ -1183,13 +1375,13 @@ fn create_mixed_repo_at(worktrees: usize, branches: usize, remote_refs: usize, r
// loose refs and uncommitted state β€” realistic, and keeps gc away from the
// dirty indexes below).
setup_fake_remote(&repo);
- add_remote_refs(remote_refs, &repo);
+ add_remote_tracking_refs(remote_tracking_refs, &repo);
run_git(&repo, &["gc", "-q"]);
// Linked worktrees are siblings named `<repo-dir>.<branch>` (worktrunk
// convention), derived from the repo's own directory name so the path is
// correct whether the repo is the tempdir's `repo` or a custom `setup` path.
- for j in 0..worktrees {
+ for j in 0..linked_worktrees {
let branch = format!("wt-{j:04}");
let wt = linked_worktree_path(&repo, &branch);
run_git(
@@ -1230,12 +1422,12 @@ fn create_mixed_repo_at(worktrees: usize, branches: usize, remote_refs: usize, r
/// `wt step prune` integration-checks every linked worktree and local branch,
/// then removes the integrated ones. Two populations drive its cost:
///
-/// - **Candidates** (`merged` of each): squash-merged worktrees
+/// - **Candidates** (`candidate_pairs`): squash-merged worktrees
/// (`merged-wt-N`) and squash-merged orphan branches (`merged-br-N`). Each
/// carries its own commits whose content also landed on main as a single
/// squash commit, so it is integrated *by content* (the `merge-tree` probes),
/// not by ancestry β€” the post-PR-squash shape prune typically removes.
-/// - **Backdrop** (`unmerged` of each): two-sided-diverged linked worktrees
+/// - **Backdrop** (`backdrop_pairs`): two-sided-diverged linked worktrees
/// and orphan branches (`add_diverged_backdrop` β€” forked at points spread
/// across history, with their own commits, while main advanced past them).
/// Scanned on every run, never removed β€” the steady state that dominates
@@ -1244,64 +1436,45 @@ fn create_mixed_repo_at(worktrees: usize, branches: usize, remote_refs: usize, r
///
/// The main history is mature (200 commits, 100 files) so `git status` and the
/// integration probes pay realistic per-worktree costs.
-pub fn create_prune_repo_at(merged: usize, unmerged: usize, base_path: &Path) {
- let config = RepoConfig {
+fn build_prune_repo_at(candidate_pairs: usize, backdrop_pairs: usize, base_path: &Path) {
+ let config = FlatRepoConfig {
commits_on_main: 200,
files: 100,
- branches: 0,
+ branchless_branches: 0,
commits_per_branch: 0,
- worktrees: 1,
+ total_worktrees: 1,
worktree_commits_ahead: 0,
worktree_uncommitted_files: 0,
};
- create_repo_at(&config, base_path);
- add_prune_populations(base_path, merged, unmerged);
+ build_flat_repo_at(&config, base_path);
+ add_prune_populations(base_path, candidate_pairs, backdrop_pairs);
// The squash commits advanced main past the fake remote ref written by
- // `create_repo_at`; refresh so origin/main tracks the final tip.
+ // `build_flat_repo_at`; refresh so origin/main tracks the final tip.
setup_fake_remote(base_path);
}
-/// Create an owned synthetic `wt step prune` fixture.
-pub fn create_prune_repo(merged: usize, unmerged: usize) -> FixtureRepo {
- FixtureRepo::create(|repo| create_prune_repo_at(merged, unmerged, repo))
-}
-
/// Add `count` squash-merged worktrees (`merged-wt-N`) and `count`
/// squash-merged orphan branches (`merged-br-N`) to an existing repo.
///
-/// Each branch gets its own commits, then the default branch (whatever the
-/// primary worktree has checked out β€” `main` on the synthetic fixtures,
-/// `master` on rust-lang/rust) takes the same content as one
+/// Each branch gets its own commits, then the default branch checked out in
+/// the primary worktree takes the same content as one
/// `git merge --squash` commit β€” integrated by content, so `wt step prune`
/// detects it via the merge-tree probes and removes it.
///
-/// `round` uniquifies the committed file names. A live-prune benchmark removes
-/// these candidates every iteration and re-creates them with an incremented
-/// `round`; reusing a round's file names would make the squash merge empty
-/// (the content is already on main) and the `git commit` fail. Branch names
-/// intentionally do NOT carry the round: prune deletes them each iteration,
-/// and a name collision on re-creation fails loudly β€” surfacing a prune run
-/// that didn't remove what the benchmark expected.
-pub fn add_squash_merged(repo_path: &Path, count: usize, round: usize) {
+pub fn add_squash_merged(repo_path: &Path, count: usize) {
let default_branch = capture_git(repo_path, &["rev-parse", "--abbrev-ref", "HEAD"]);
- // Two commits in `dir`, each adding a round-uniquified file (the branch
- // name already carries the candidate index). The add is targeted β€” a bare
- // `git add .` would rescan the whole tree, which on rust-lang/rust costs
- // seconds per commit.
+ // Two commits in `dir`, each adding a branch-uniquified file. The add is
+ // targeted β€” a bare `git add .` would rescan the whole tree, which on
+ // rust-lang/rust costs seconds per commit.
let commit_branch_content = |dir: &Path, branch: &str| {
for j in 0..2 {
- let name = format!("{}_{round}_{j}.rs", branch.replace('-', "_"));
- std::fs::write(dir.join(&name), format!("// {branch} {round}/{j}\n")).unwrap();
+ let name = format!("{}_{j}.rs", branch.replace('-', "_"));
+ std::fs::write(dir.join(&name), format!("// {branch} {j}\n")).unwrap();
run_git(dir, &["add", &name]);
run_git(
dir,
- &[
- "commit",
- "-q",
- "-m",
- &format!("{branch} commit {j} (round {round})"),
- ],
+ &["commit", "-q", "-m", &format!("{branch} commit {j}")],
);
}
};
@@ -1310,12 +1483,7 @@ pub fn add_squash_merged(repo_path: &Path, count: usize, round: usize) {
run_git(repo_path, &["merge", "--squash", "-q", branch]);
run_git(
repo_path,
- &[
- "commit",
- "-q",
- "-m",
- &format!("Squash-merge {branch} (round {round})"),
- ],
+ &["commit", "-q", "-m", &format!("Squash-merge {branch}")],
);
};
@@ -1348,250 +1516,38 @@ pub fn add_squash_merged(repo_path: &Path, count: usize, round: usize) {
}
/// Add the two populations that turn a repo into a `wt step prune` workload:
-/// `unmerged` two-sided-diverged worktrees and branches (`add_diverged_backdrop`
-/// β€” the backdrop prune scans every run but never removes) and `merged`
+/// `backdrop_pairs` two-sided-diverged worktrees and branches (`add_diverged_backdrop`
+/// β€” the backdrop prune scans every run but never removes) and `candidate_pairs`
/// squash-merged candidate pairs (`add_squash_merged` β€” what prune removes).
///
-/// The base repo is the only thing the synthetic ([`create_prune_repo_at`]) and
-/// rust-scale (`create_prune_real_repo_at`) prune fixtures differ in; both layer
-/// these identical populations on top, so keeping the layering in one place
-/// stops the two fixtures from drifting.
-fn add_prune_populations(base_path: &Path, merged: usize, unmerged: usize) {
- add_diverged_backdrop(base_path, unmerged, unmerged);
- add_squash_merged(base_path, merged, 0);
+/// The base repo is the only thing the synthetic and large-repository prune
+/// recipes differ in. Both layer these populations on top.
+fn add_prune_populations(base_path: &Path, candidate_pairs: usize, backdrop_pairs: usize) {
+ add_diverged_backdrop(base_path, backdrop_pairs, backdrop_pairs);
+ add_squash_merged(base_path, candidate_pairs);
}
-/// Default populations for the rust-scale prune fixture (`prune-real`):
+/// Default populations for the large-repository prune fixture:
/// 12 squash-merged candidates of each kind + 24 unmerged worktrees and
/// branches β†’ 36 linked worktrees, and a live prune that removes 24
/// candidates while keeping 72 unmerged items β€” the "dozens of worktrees,
/// lots removed, lots kept" shape where prune takes multiple seconds.
-pub const PRUNE_REAL_MERGED: usize = 12;
-pub const PRUNE_REAL_UNMERGED: usize = 24;
-
-/// Create a rust-lang/rust-scale `wt step prune` workload at `base_path`.
-///
-/// Local-clones the cached rust repo (`ensure_rust_repo` β€” first call clones
-/// from the network, minutes) and adds the same two populations as
-/// [`create_prune_repo_at`]: `merged` squash-merged candidates of each kind
-/// ([`add_squash_merged`]) against a two-sided-diverged backdrop of `unmerged`
-/// worktrees and branches forked across the last 5000 commits
-/// (`add_diverged_backdrop`). This is the shape where prune's costs are
-/// real β€” merge-base walks over deep history, `merge-tree` three-ways over
-/// ~400 MiB trees, `git status` over ~60k files per worktree β€” and reproduces
-/// the "prune takes seconds" experience that small synthetic fixtures can't
-/// (their probes bottom out at subprocess-spawn cost).
-///
-/// Each linked worktree materializes a full working tree: ~400 MiB and ~3 s
-/// per worktree, so the default populations build in minutes and take ~15 GiB.
-/// Prefer [`ensure_prune_real_repo`], which builds once into
-/// `target/wt-perf/bench-repos` and repairs consumed candidates on later runs.
-fn create_prune_real_repo_at(merged: usize, unmerged: usize, base_path: &Path) {
- clone_rust_repo_at(base_path);
- add_prune_populations(base_path, merged, unmerged);
-}
-
-/// How a cached prune fixture compares to its expected populations.
-#[derive(Debug, PartialEq, Eq)]
-enum PruneFixtureState {
- /// Backdrop and candidates all present.
- Intact,
- /// Backdrop intact, candidates fully consumed β€” a live prune ran.
- /// Repairable by re-running [`add_squash_merged`] with a fresh round.
- Consumed,
- /// Anything else (partial removal, corruption) β€” rebuild from scratch.
- Broken,
-}
-
-/// Classify a prune fixture ([`create_prune_repo_at`] /
-/// `create_prune_real_repo_at` layout) against its expected populations.
-///
-/// Counts are the fixture's invariants: `1 + unmerged + merged` worktrees,
-/// `2 * unmerged` `feature-*` branches (worktree + orphan), `2 * merged`
-/// `merged-*` branches. A live prune removes exactly the `merged-*` items,
-/// which is the [`PruneFixtureState::Consumed`] signature.
-fn prune_fixture_state(repo: &Path, merged: usize, unmerged: usize) -> PruneFixtureState {
- if !run_git_ok(repo, &["rev-parse", "HEAD"]) {
- return PruneFixtureState::Broken;
- }
- let worktrees = capture_git(repo, &["worktree", "list", "--porcelain"])
- .lines()
- .filter(|l| l.starts_with("worktree "))
- .count();
- let branches = capture_git(
- repo,
- &["for-each-ref", "--format=%(refname:short)", "refs/heads"],
- );
- let merged_branches = branches
- .lines()
- .filter(|b| b.starts_with("merged-"))
- .count();
- let feature_branches = branches
- .lines()
- .filter(|b| b.starts_with("feature-"))
- .count();
-
- if feature_branches != 2 * unmerged {
- return PruneFixtureState::Broken;
- }
- if worktrees == 1 + unmerged + merged && merged_branches == 2 * merged {
- PruneFixtureState::Intact
- } else if worktrees == 1 + unmerged && merged_branches == 0 {
- PruneFixtureState::Consumed
- } else {
- PruneFixtureState::Broken
- }
-}
-
-/// The next [`add_squash_merged`] round for a fixture repo, derived from the
-/// repo itself: each completed round leaves `merged_br_0_<round>_*.rs` files
-/// on the default branch's tip tree (the squash commits survive candidate
-/// removal), so the number of distinct rounds already landed IS the next
-/// round index. Derived rather than stored β€” a sidecar counter can desync
-/// from the repo (interrupted repair, hand cleanup) and turn a ~1-minute
-/// repair into a name-collision panic.
-fn next_squash_round(repo: &Path) -> usize {
- capture_git(repo, &["ls-tree", "--name-only", "HEAD"])
- .lines()
- .filter(|l| l.starts_with("merged_br_0_") && l.ends_with("_0.rs"))
- .count()
-}
-
-/// Get or build the cached rust-scale prune fixture, returning the repo path.
-///
-/// The fixture lives at `target/wt-perf/bench-repos/rust-prune-<merged>-<unmerged>/repo`
-/// (worktrees as siblings) so its minutes-long build (`create_prune_real_repo_at`)
-/// is paid once, not per bench run. On reuse it is validated by
-/// `prune_fixture_state`:
-///
-/// - `Intact` β†’ returned as-is (dry runs don't mutate it).
-/// - `Consumed` β€” a live `wt step prune` removed the candidates β€” β†’ repaired
-/// in place by re-running [`add_squash_merged`] with the next round
-/// (`next_squash_round`), so a live-prune measurement costs a ~1-minute
-/// repair, not a full rebuild.
-/// - `Broken` (interrupted prune or build, corruption) β†’ wiped and rebuilt.
-///
-/// Deleted worktree indexes (a stray `wt-perf invalidate` / `timeline --cold`
-/// against the fixture) are healed first with `restore_worktree_indexes` β€”
-/// without an index, `git status` reports every tracked file as a staged
-/// deletion and prune's clean-worktree gate silently drops the worktree
-/// candidates. Safe here because the fixture's only dirt is untracked files.
-///
-/// No cross-process locking: two concurrent callers (e.g. `cargo bench
-/// --bench prune` while `wt-perf setup prune-real` is mid-build) can classify
-/// each other's half-built tree as `Broken` and wipe it. Don't run two
-/// builders at once; the same limitation applies to `ensure_rust_repo`.
-pub fn ensure_prune_real_repo(merged: usize, unmerged: usize) -> PathBuf {
- let cache_dir = bench_repos_dir().join(format!("rust-prune-{merged}-{unmerged}"));
- let repo = cache_dir.join("repo");
-
- if repo.exists() {
- let worktrees_dir = repo.join(".git/worktrees");
- let index_missing = !repo.join(".git/index").exists()
- || std::fs::read_dir(&worktrees_dir).is_ok_and(|entries| {
- entries
- .flatten()
- .any(|entry| !entry.path().join("index").exists())
- });
- if index_missing {
- eprintln!("Restoring invalidated worktree indexes...");
- restore_worktree_indexes(&repo);
- }
- match prune_fixture_state(&repo, merged, unmerged) {
- PruneFixtureState::Intact => {
- eprintln!("Using cached prune fixture at {}", repo.display());
- return repo;
- }
- PruneFixtureState::Consumed => {
- let round = next_squash_round(&repo);
- eprintln!(
- "Re-creating {merged} consumed squash-merged candidate pairs (round {round})..."
- );
- add_squash_merged(&repo, merged, round);
- return repo;
- }
- PruneFixtureState::Broken => {
- eprintln!("Cached prune fixture unusable, rebuilding...");
- }
- }
- }
-
- eprintln!(
- "Building prune fixture: {} rust worktrees at ~3s each (one-time, cached)...",
- merged + unmerged
- );
- // Clear remnants unconditionally: an interrupted build or rebuild can
- // leave sibling worktree dirs without `repo`, and `git worktree add`
- // fails on an existing non-empty destination.
- if cache_dir.exists() {
- std::fs::remove_dir_all(&cache_dir).unwrap();
- }
- std::fs::create_dir_all(&cache_dir).unwrap();
- create_prune_real_repo_at(merged, unmerged, &repo);
- repo
-}
+pub const PRUNE_LARGE_REPOSITORY_CANDIDATE_PAIRS: usize = 12;
+pub const PRUNE_LARGE_REPOSITORY_BACKDROP_PAIRS: usize = 24;
/// Canonicalize path without Windows `\\?\` prefix.
pub fn canonicalize(path: &Path) -> std::io::Result<PathBuf> {
dunce::canonicalize(path)
}
-/// Parse a `wt-perf setup` config string.
-///
-/// Supported formats:
-/// - `typical-N` - typical repo with N worktrees
-/// - `branches-N` - N branches with 1 commit each
-/// - `branches-N-M` - N branches with M commits each
-/// - `divergent` - many divergent branches (GH #461)
-/// - `mixed-W-B[-R]` - W worktrees + B branches in varied states, plus R remote-tracking refs
-/// - `prune-M-U` - M squash-merged candidates + U unmerged (prune workload)
-/// - `picker-test` - config for wt switch interactive picker testing
-pub fn parse_config(s: &str) -> Option<SetupConfig> {
- if let Some(n) = s.strip_prefix("typical-") {
- let worktrees: usize = n.parse().ok()?;
- return Some(SetupConfig::Flat(RepoConfig::typical(worktrees)));
- }
-
- if let Some(rest) = s.strip_prefix("branches-") {
- let config = match rest.split('-').collect::<Vec<_>>().as_slice() {
- [count] => RepoConfig::branches(count.parse().ok()?, 1),
- [count, commits] => RepoConfig::branches(count.parse().ok()?, commits.parse().ok()?),
- _ => return None,
- };
- return Some(SetupConfig::Flat(config));
- }
-
- if let Some(rest) = s.strip_prefix("mixed-") {
- return match rest.split('-').collect::<Vec<_>>().as_slice() {
- [w, b] => Some(SetupConfig::Mixed {
- worktrees: w.parse().ok()?,
- branches: b.parse().ok()?,
- remote_refs: 0,
- }),
- [w, b, r] => Some(SetupConfig::Mixed {
- worktrees: w.parse().ok()?,
- branches: b.parse().ok()?,
- remote_refs: r.parse().ok()?,
- }),
- _ => None,
- };
- }
-
- if let Some((merged, unmerged)) = parse_pair(s, "prune-") {
- return Some(SetupConfig::Prune { merged, unmerged });
- }
-
- match s {
- "divergent" => Some(SetupConfig::Flat(RepoConfig::many_divergent_branches())),
- "picker-test" => Some(SetupConfig::Flat(RepoConfig::picker_test())),
- _ => None,
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
+ fn create_flat(config: &FlatRepoConfig) -> FixtureRepo {
+ FixtureRepo::create(|repo| build_flat_repo_at(config, repo))
+ }
+
/// Sorted `git status --porcelain` lines for a worktree.
///
/// Reads raw stdout rather than going through `capture_git`, which trims:
@@ -1652,50 +1608,167 @@ mod tests {
}
}
- /// Regression: `create_repo_at` ends with `git gc`, which packs every loose
- /// ref into `.git/packed-refs` and prunes the loose copies. A prior version
- /// of `invalidate_caches_auto` deleted `packed-refs`, which after gc was
- /// the only copy of `refs/heads/main` β€” leaving the repo with no resolvable
- /// refs and breaking the `with_vars` alias bench at `dispatch/with_vars/*`.
#[test]
- fn invalidate_preserves_refs_after_gc() {
- let fixture = create_repo(&RepoConfig {
- commits_on_main: 1,
- files: 1,
- branches: 0,
+ fn fixture_lock_excludes_an_independent_handle() {
+ let temp = tempfile::tempdir().unwrap();
+ let path = temp.path().join("fixture.lock");
+ let first = acquire_exclusive_lock(&path);
+ let second = OpenOptions::new().write(true).open(&path).unwrap();
+
+ assert!(
+ second.try_lock_exclusive().is_err(),
+ "another process handle must not acquire a leased fixture"
+ );
+ FileExt::unlock(&first).unwrap();
+ second.try_lock_exclusive().unwrap();
+ FileExt::unlock(&second).unwrap();
+ }
+
+ #[test]
+ fn large_repository_source_rejects_a_missing_pinned_commit_object() {
+ let temp = tempfile::tempdir().unwrap();
+ init_bench_repo(temp.path());
+ std::fs::write(
+ temp.path().join(".git/refs/heads/main"),
+ format!("{LARGE_REPOSITORY_REVISION}\n"),
+ )
+ .unwrap();
+
+ assert!(
+ !large_repository_source_matches(temp.path()),
+ "a textual ref without its commit object is not a usable clone source"
+ );
+ }
+
+ /// Cache invalidation must never change the repository state presented to
+ /// the command being benchmarked. In particular, deleting a real index is
+ /// not a cold-cache simulation: git reads the missing index as every
+ /// tracked file being staged for deletion. Refs are part of the same
+ /// contract: fixture creation packs them during `git gc`, so `packed-refs`
+ /// is primary storage rather than a disposable cache.
+ #[test]
+ fn invalidate_preserves_repository_state_and_clears_caches() {
+ let fixture = create_flat(&FlatRepoConfig {
+ commits_on_main: 2,
+ files: 2,
+ branchless_branches: 0,
commits_per_branch: 0,
- worktrees: 1,
- worktree_commits_ahead: 0,
+ total_worktrees: 2,
+ worktree_commits_ahead: 1,
worktree_uncommitted_files: 0,
});
- let repo_path = fixture.path().to_path_buf();
+ let repo = fixture.path().to_path_buf();
+ let linked = fixture.worktree_path("feature-wt-1");
+
+ for (worktree, suffix) in [(&repo, "primary"), (&linked, "linked")] {
+ let tracked = worktree.join("src/file_0.rs");
+ let mut content = std::fs::read_to_string(&tracked).unwrap();
+ content.push_str(&format!("\n// staged in {suffix}\n"));
+ std::fs::write(&tracked, &content).unwrap();
+ run_git(worktree, &["add", "src/file_0.rs"]);
+ content.push_str(&format!("// unstaged in {suffix}\n"));
+ std::fs::write(&tracked, content).unwrap();
+ std::fs::write(
+ worktree.join(format!("untracked-{suffix}.txt")),
+ "untracked\n",
+ )
+ .unwrap();
+ }
- let rev_parse_main = || {
- git_command()
- .args(["rev-parse", "main"])
- .current_dir(&repo_path)
- .output()
- .unwrap()
+ let git_dir = resolve_git_common_dir(&repo).unwrap();
+ run_git(&repo, &["commit-graph", "write", "--reachable"]);
+ let commit_graph = git_dir.join("objects/info/commit-graph");
+ assert!(
+ commit_graph.exists(),
+ "setup precondition: commit graph exists"
+ );
+ let cache_dir = git_dir.join("wt/cache/probe");
+ std::fs::create_dir_all(&cache_dir).unwrap();
+ std::fs::write(cache_dir.join("entry"), "cached\n").unwrap();
+ run_git(&repo, &["config", "worktrunk.default-branch", "main"]);
+
+ let index_path = |worktree: &Path| {
+ let path = PathBuf::from(capture_git(worktree, &["rev-parse", "--git-path", "index"]));
+ if path.is_absolute() {
+ path
+ } else {
+ worktree.join(path)
+ }
};
+ let primary_index = index_path(&repo);
+ let linked_index = index_path(&linked);
+ assert!(primary_index.exists(), "setup precondition: primary index");
+ assert!(linked_index.exists(), "setup precondition: linked index");
- let before = rev_parse_main();
- assert!(
- before.status.success(),
- "setup precondition: `rev-parse main` succeeds"
+ let primary_status = status_lines(&repo);
+ let linked_status = status_lines(&linked);
+ assert_eq!(
+ primary_status,
+ ["?? untracked-primary.txt", "MM src/file_0.rs"]
+ );
+ assert_eq!(
+ linked_status,
+ ["?? untracked-linked.txt", "MM src/file_0.rs"]
);
+ let refs = capture_git(
+ &repo,
+ &[
+ "for-each-ref",
+ "--format=%(refname) %(objectname)",
+ "refs/heads",
+ ],
+ );
+ let worktree_listing = capture_git(&repo, &["worktree", "list", "--porcelain"]);
- invalidate_caches_auto(&repo_path);
+ // Invalidate through the linked worktree to exercise common-dir
+ // resolution as well as the cache policy itself.
+ invalidate_caches_auto(&linked);
- let after = rev_parse_main();
+ assert_eq!(status_lines(&repo), primary_status);
+ assert_eq!(status_lines(&linked), linked_status);
+ assert_eq!(
+ capture_git(
+ &repo,
+ &[
+ "for-each-ref",
+ "--format=%(refname) %(objectname)",
+ "refs/heads",
+ ],
+ ),
+ refs
+ );
+ assert_eq!(
+ capture_git(&repo, &["worktree", "list", "--porcelain"]),
+ worktree_listing
+ );
+ assert!(primary_index.exists(), "primary index must survive");
+ assert!(linked_index.exists(), "linked index must survive");
+ assert!(!commit_graph.exists(), "commit graph must be cleared");
+ assert!(
+ !git_dir.join("wt/cache").exists(),
+ "wt cache must be cleared"
+ );
assert!(
- after.status.success(),
- "`refs/heads/main` must survive `invalidate_caches_auto` (stderr: {})",
- String::from_utf8_lossy(&after.stderr)
+ !run_git_ok(&repo, &["config", "--get", "worktrunk.default-branch"]),
+ "default-branch cache must be cleared"
);
- assert_eq!(before.stdout, after.stdout);
}
- /// The `full` fixture's contract: [`create_mixed_repo`] promises a
+ /// An invalid cache shape stands in for filesystem failures that are hard
+ /// to induce portably. Invalidation must fail loudly rather than silently
+ /// benchmark a warm cache after cleanup did not happen.
+ #[test]
+ #[should_panic(expected = "failed to remove cache directory")]
+ fn invalidate_reports_cache_removal_errors() {
+ let fixture = FixtureRecipe::Typical { total_worktrees: 1 }.create();
+ let git_dir = resolve_git_common_dir(fixture.path()).unwrap();
+ std::fs::create_dir_all(git_dir.join("wt")).unwrap();
+ std::fs::write(git_dir.join("wt/cache"), "not a directory\n").unwrap();
+
+ invalidate_probe_caches(fixture.path());
+ }
+
+ /// The `full` fixture's contract: [`FixtureRecipe::Mixed`] promises a
/// deterministic `index % 4` rotation of branch and worktree states, and
/// every `wt list` gate the `full` bench exercises hangs off that rotation.
/// Nothing else pins it β€” the bench measures one wall time, so a generator
@@ -1707,7 +1780,12 @@ mod tests {
// Two full rotations of each 4-state cycle, so a state that collapsed
// into its neighbour fails on both of its indices rather than one.
const N: usize = 8;
- let fixture = create_mixed_repo(N, N, 0);
+ let fixture = FixtureRecipe::Mixed {
+ linked_worktrees: N,
+ branchless_branches: N,
+ remote_tracking_refs: 0,
+ }
+ .create();
let repo = fixture.path().to_path_buf();
let main = capture_git(&repo, &["rev-parse", "main"]);
@@ -1803,144 +1881,64 @@ mod tests {
/// integrated *by content* β€” `git merge-tree --write-tree main <branch>`
/// yields main's own tree (merging it adds nothing). That's exactly the
/// probe `wt step prune`'s integration check runs, so if this drifts, the
- /// prune benchmark stops removing anything. Round 1 re-creation must keep
- /// the property (unique file content per round).
+ /// prune benchmark stops removing anything.
#[test]
fn squash_merged_fixture_is_content_integrated() {
- let fixture = create_repo(&RepoConfig {
+ let fixture = create_flat(&FlatRepoConfig {
commits_on_main: 3,
files: 2,
- branches: 0,
+ branchless_branches: 0,
commits_per_branch: 0,
- worktrees: 1,
+ total_worktrees: 1,
worktree_commits_ahead: 0,
worktree_uncommitted_files: 0,
});
let repo_path = fixture.path().to_path_buf();
- for round in 0..2 {
- add_squash_merged(&repo_path, 1, round);
+ add_squash_merged(&repo_path, 1);
- let main_tree = git_command()
- .args(["rev-parse", "main^{tree}"])
+ let main_tree = git_command()
+ .args(["rev-parse", "main^{tree}"])
+ .current_dir(&repo_path)
+ .output()
+ .unwrap();
+ for branch in ["merged-wt-0", "merged-br-0"] {
+ let merged_tree = git_command()
+ .args(["merge-tree", "--write-tree", "main", branch])
.current_dir(&repo_path)
.output()
.unwrap();
- for branch in ["merged-wt-0", "merged-br-0"] {
- let merged_tree = git_command()
- .args(["merge-tree", "--write-tree", "main", branch])
- .current_dir(&repo_path)
- .output()
- .unwrap();
- assert!(
- merged_tree.status.success(),
- "merge-tree failed (round {round})"
- );
- assert_eq!(
- String::from_utf8_lossy(&merged_tree.stdout).trim(),
- String::from_utf8_lossy(&main_tree.stdout).trim(),
- "{branch} must merge into main without adding changes (round {round})"
- );
- }
-
- // Simulate the live benchmark's per-iteration cleanup before the
- // next round re-creates the candidates.
- let wt_path = fixture.worktree_path("merged-wt-0");
- run_git(
- &repo_path,
- &["worktree", "remove", "--force", wt_path.to_str().unwrap()],
+ assert!(merged_tree.status.success(), "merge-tree failed");
+ assert_eq!(
+ String::from_utf8_lossy(&merged_tree.stdout).trim(),
+ String::from_utf8_lossy(&main_tree.stdout).trim(),
+ "{branch} must merge into main without adding changes"
);
- run_git(&repo_path, &["branch", "-D", "merged-wt-0", "merged-br-0"]);
}
}
- /// The classifier that decides whether the cached rust-scale fixture is
- /// reusable, repairable, or must be rebuilt ([`ensure_prune_real_repo`]).
- /// Exercised on the synthetic fixture, which shares the exact layout.
+ /// A zero-size spread is valid and must not divide by zero.
#[test]
- fn prune_fixture_state_classifies_lifecycle() {
- let fixture = create_prune_repo(1, 2);
- let repo_path = fixture.path().to_path_buf();
-
- assert_eq!(
- prune_fixture_state(&repo_path, 1, 2),
- PruneFixtureState::Intact
- );
- // Wrong expected populations don't match this repo.
- assert_eq!(
- prune_fixture_state(&repo_path, 2, 2),
- PruneFixtureState::Broken
- );
-
- // Partial consumption (worktree candidate gone, branches still there)
- // is Broken β€” an interrupted live prune needs a rebuild.
- let wt_path = fixture.worktree_path("merged-wt-0");
- run_git(
- &repo_path,
- &["worktree", "remove", "--force", wt_path.to_str().unwrap()],
- );
- assert_eq!(
- prune_fixture_state(&repo_path, 1, 2),
- PruneFixtureState::Broken
- );
-
- // Full consumption β€” exactly what a live prune leaves behind.
- run_git(&repo_path, &["branch", "-D", "merged-wt-0", "merged-br-0"]);
- assert_eq!(
- prune_fixture_state(&repo_path, 1, 2),
- PruneFixtureState::Consumed
- );
-
- // Repair restores Intact, with the round derived from the repo
- // itself (round 0's squash commits survive candidate removal).
- assert_eq!(next_squash_round(&repo_path), 1);
- add_squash_merged(&repo_path, 1, next_squash_round(&repo_path));
- assert_eq!(next_squash_round(&repo_path), 2);
- assert_eq!(
- prune_fixture_state(&repo_path, 1, 2),
- PruneFixtureState::Intact
- );
-
- // A missing backdrop branch is Broken.
- run_git(&repo_path, &["branch", "-D", "feature-000"]);
- assert_eq!(
- prune_fixture_state(&repo_path, 1, 2),
- PruneFixtureState::Broken
- );
- }
-
- /// Regression: degenerate `count` values must not panic. `count == 0`
- /// divided into `5000`, and `count > 5000` flooring `step` to 0 for
- /// `step_by`, both panicked before the `max(1)` guards.
- #[test]
- fn history_spread_handles_degenerate_counts() {
- let fixture = create_repo(&RepoConfig {
+ fn history_spread_handles_zero_branches() {
+ let fixture = create_flat(&FlatRepoConfig {
commits_on_main: 3,
files: 1,
- branches: 0,
+ branchless_branches: 0,
commits_per_branch: 0,
- worktrees: 1,
+ total_worktrees: 1,
worktree_commits_ahead: 0,
worktree_uncommitted_files: 0,
});
let repo_path = fixture.path().to_path_buf();
- // count == 0: no branches created, no divide-by-zero.
add_history_spread_branches(&repo_path, 0);
- // count far above the 5000 log cap: step floors to 0 without the guard.
- add_history_spread_branches(&repo_path, 6000);
}
- /// The `mixed` fixture's second documented contract: either dimension may
- /// be `0` (`wt-perf setup mixed-3-0` is a worktrees-only repo). The branch
- /// loop divides by `branches` to fan fork points across history, so a zero
- /// there is a divide-by-zero the instant the body runs β€” it is safe only
- /// because `0..0` never enters, which is exactly the kind of guarantee a
- /// later "defensive" `branches.max(1)` would quietly break. Assert the
- /// resulting populations, not merely that nothing panicked, so such a fix
- /// fails here instead of silently adding a branch nobody asked for.
+ /// The `mixed` fixture's population contract. Either local dimension may
+ /// be zero, and the requested remote-tracking refs are additive to the
+ /// `origin/main` and `origin/HEAD` pair every synthetic fixture carries.
#[test]
- fn mixed_fixture_allows_either_dimension_to_be_zero() {
+ fn mixed_fixture_preserves_each_population() {
let refs = |repo: &Path, glob: &str| {
capture_git(repo, &["for-each-ref", "--format=%(refname:short)", glob])
.lines()
@@ -1955,18 +1953,29 @@ mod tests {
- 1
};
- // The two dimensions share no state, so covering each zero once spans
- // the contract β€” a both-zero repo just skips both loops.
- let fixture = create_mixed_repo(3, 0, 0);
+ // Cover each local zero once and add remote refs to one fixture.
+ let fixture = FixtureRecipe::Mixed {
+ linked_worktrees: 3,
+ branchless_branches: 0,
+ remote_tracking_refs: 5,
+ }
+ .create();
let repo = fixture.path().to_path_buf();
assert_eq!(refs(&repo, "refs/heads/br-*"), 0, "no branchless branches");
assert_eq!(refs(&repo, "refs/heads/wt-*"), 3);
+ assert_eq!(refs(&repo, "refs/remotes/origin/remote-only-*"), 5);
assert_eq!(linked(&repo), 3);
- let fixture = create_mixed_repo(0, 3, 0);
+ let fixture = FixtureRecipe::Mixed {
+ linked_worktrees: 0,
+ branchless_branches: 3,
+ remote_tracking_refs: 0,
+ }
+ .create();
let repo = fixture.path().to_path_buf();
assert_eq!(refs(&repo, "refs/heads/br-*"), 3);
assert_eq!(refs(&repo, "refs/heads/wt-*"), 0, "no worktree branches");
+ assert_eq!(refs(&repo, "refs/remotes/origin/remote-only-*"), 0);
assert_eq!(linked(&repo), 0);
}
@@ -1977,16 +1986,17 @@ mod tests {
/// depth rather than bottoming out at the tip).
///
/// Deliberately built with unequal populations: the sole production caller
- /// passes `unmerged` for both, so a swap of the `(worktrees, branches)`
+ /// passes `backdrop_pairs` for both, so a swap of the
+ /// `(linked_worktrees, branchless_branches)`
/// parameters is invisible there and would be caught only here.
#[test]
fn diverged_backdrop_is_unintegrated_and_spread_across_history() {
- let fixture = create_repo(&RepoConfig {
+ let fixture = create_flat(&FlatRepoConfig {
commits_on_main: 40,
files: 2,
- branches: 0,
+ branchless_branches: 0,
commits_per_branch: 0,
- worktrees: 1,
+ total_worktrees: 1,
worktree_commits_ahead: 0,
worktree_uncommitted_files: 0,
});
diff --git a/tests/helpers/wt-perf/src/main.rs b/tests/helpers/wt-perf/src/main.rs
index 7afe91736..c0a9d797f 100644
--- a/tests/helpers/wt-perf/src/main.rs
+++ b/tests/helpers/wt-perf/src/main.rs
@@ -8,10 +8,7 @@ use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
use clap::{Parser, Subcommand};
-use wt_perf::{
- PRUNE_REAL_MERGED, PRUNE_REAL_UNMERGED, canonicalize, ensure_prune_real_repo,
- invalidate_caches_auto, parse_config, parse_pair, wt_perf_fixture_dir,
-};
+use wt_perf::{FixtureRecipe, canonicalize, invalidate_caches_auto};
#[derive(Parser)]
#[command(name = "wt-perf")]
@@ -25,20 +22,14 @@ struct Cli {
enum Commands {
/// Set up a benchmark repository
Setup {
- /// Config name: typical-N, branches-N, branches-N-M, divergent, mixed-W-B, prune-M-U, prune-real[-M-U], picker-test
- config: String,
+ #[command(subcommand)]
+ recipe: FixtureRecipe,
- /// Directory to create repo in (default: target/wt-perf)
- #[arg(long)]
+ /// Primary worktree path; must not already exist
+ #[arg(long, global = true)]
path: Option<PathBuf>,
},
- /// Invalidate git caches for cold benchmarks
- Invalidate {
- /// Path to the repository
- repo: PathBuf,
- },
-
/// Parse a trace.jsonl and output Chrome Trace Format JSON
#[command(after_long_help = r#"EXAMPLES:
# Capture a trace, then convert it. --progressive is required β€” without it,
@@ -76,7 +67,7 @@ enum Commands {
wt-perf timeline --cold -- list
# Cold run against a specific repo (setup prints the exact path)
- wt-perf timeline --cold -- -C target/wt-perf/typical-1 list
+ wt-perf timeline --cold -- -C /tmp/wt-typical-1 list
# Chrome Trace Format JSON for Perfetto
wt-perf timeline --chrome -- list > trace.json
@@ -100,93 +91,49 @@ fn main() {
let cli = Cli::parse();
match cli.command {
- Commands::Setup { config, path } => {
- // `prune-real[-M-U]`: cache-managed rust-scale fixture (built once
- // under target/wt-perf/bench-repos, repaired after a live prune consumes
- // its candidates) β€” takes no --path and never offers cleanup.
- // Tested before parse_config so its `prune-` arm never sees it.
- let prune_real = if config == "prune-real" {
- Some((PRUNE_REAL_MERGED, PRUNE_REAL_UNMERGED))
+ Commands::Setup { recipe, path } => {
+ let Some(path) = path else {
+ eprintln!("Missing required --path for benchmark fixture setup.");
+ std::process::exit(2);
+ };
+ let absolute_path = if path.is_absolute() {
+ path
} else {
- parse_pair(&config, "prune-real-")
+ std::env::current_dir().unwrap().join(path)
};
- if let Some((merged, unmerged)) = prune_real {
- if path.is_some() {
+ let parent = absolute_path.parent().unwrap();
+ let base_path = canonicalize(parent)
+ .unwrap_or_else(|error| {
eprintln!(
- "prune-real fixtures are managed under {}; --path is not supported",
- wt_perf_fixture_dir().join("bench-repos").display()
+ "Could not resolve destination parent {}: {error}",
+ parent.display()
);
std::process::exit(1);
+ })
+ .join(absolute_path.file_name().unwrap());
+ if let Err(error) = std::fs::create_dir(&base_path) {
+ if error.kind() == std::io::ErrorKind::AlreadyExists {
+ eprintln!(
+ "Destination already exists: {}. Choose a new --path or remove it first.",
+ base_path.display()
+ );
+ } else {
+ eprintln!(
+ "Could not reserve destination {}: {error}",
+ base_path.display()
+ );
}
- let repo = ensure_prune_real_repo(merged, unmerged);
- eprintln!(
- "Ready: main @ {}, {} worktrees, {} branches",
- repo.display(),
- merged + unmerged + 1,
- merged + unmerged
- );
- eprintln!();
- eprintln!(
- " wt-perf timeline -- -C {} step prune --dry-run --min-age 0s",
- repo.display()
- );
- eprintln!(
- " wt-perf timeline -- -C {} step prune --min-age 0s # live; next setup/bench run re-creates the candidates",
- repo.display()
- );
- // No `wt-perf invalidate` hint: deleting this fixture's
- // worktree indexes flips prune's clean-worktree gate and
- // degrades every later run (ensure_prune_real_repo heals it,
- // but only on the next setup/bench call).
- return;
- }
-
- let spec = parse_config(&config).unwrap_or_else(|| {
- eprintln!("Unknown config: {}", config);
- eprintln!();
- eprintln!("Available configs:");
- eprintln!(
- " typical-N - Typical repo with N worktrees (500 commits, 100 files)"
- );
- eprintln!(" branches-N - N branches with 1 commit each");
- eprintln!(" branches-N-M - N branches with M commits each");
- eprintln!(" divergent - 200 branches Γ— 20 commits (GH #461 scenario)");
- eprintln!(" mixed-W-B - W worktrees + B branches in varied states");
- eprintln!(
- " prune-M-U - M squash-merged candidates + U unmerged worktrees/branches (wt step prune workload)"
- );
- eprintln!(
- " prune-real[-M-U] - rust-lang/rust clone + M squash-merged candidates + U unmerged worktrees/branches, cached under target/wt-perf/bench-repos (default {PRUNE_REAL_MERGED}-{PRUNE_REAL_UNMERGED}; first run clones from network)"
- );
- eprintln!(" picker-test - Config for wt switch interactive picker testing");
std::process::exit(1);
- });
-
- let base_path = if let Some(p) = path {
- std::fs::create_dir_all(&p).unwrap();
- canonicalize(&p).unwrap()
- } else {
- let dir = wt_perf_fixture_dir().join(&config);
- if dir.exists() {
- std::fs::remove_dir_all(&dir).unwrap();
- }
- std::fs::create_dir_all(&dir).unwrap();
- canonicalize(&dir).unwrap()
- };
-
- eprintln!("Creating {} repo...", config);
- let (worktrees, branches) = spec.create_at(&base_path);
-
- let mut parts = vec![format!("main @ {}", base_path.display())];
- if worktrees > 1 {
- parts.push(format!("{} worktrees", worktrees));
- }
- if branches > 0 {
- parts.push(format!("{} branches", branches));
}
- eprintln!("Created: {}", parts.join(", "));
+
+ eprintln!("Creating fixture at {}...", base_path.display());
+ recipe.create_at(&base_path);
+ eprintln!("Created: main @ {}", base_path.display());
eprintln!();
- let example_args = if matches!(spec, wt_perf::SetupConfig::Prune { .. }) {
+ let example_args = if matches!(
+ recipe,
+ FixtureRecipe::Prune { .. } | FixtureRecipe::LargeRepositoryPrune { .. }
+ ) {
"step prune --dry-run --min-age 0s"
} else {
"list --progressive"
@@ -201,22 +148,11 @@ fn main() {
base_path.display(),
example_args
);
- eprintln!(" wt-perf invalidate {}", base_path.display());
- }
-
- Commands::Invalidate { repo } => {
- let repo = canonicalize(&repo).unwrap_or_else(|e| {
- eprintln!("Invalid repo path {}: {}", repo.display(), e);
- std::process::exit(1);
- });
-
- if !repo.join(".git").exists() {
- eprintln!("Not a git repository: {}", repo.display());
- std::process::exit(1);
- }
-
- invalidate_caches_auto(&repo);
- eprintln!("Invalidated caches for {}", repo.display());
+ eprintln!(
+ " wt-perf timeline --cold -- -C {} {}",
+ base_path.display(),
+ example_args
+ );
}
Commands::Trace { file } => {
diff --git a/tests/helpers/wt-perf/tests/cli.rs b/tests/helpers/wt-perf/tests/cli.rs
index a033d60af..1be213037 100644
--- a/tests/helpers/wt-perf/tests/cli.rs
+++ b/tests/helpers/wt-perf/tests/cli.rs
@@ -1,16 +1,170 @@
-//! Integration tests for the wt-perf trace command.
+//! Integration tests for the wt-perf CLI.
//!
//! In-package so cargo builds the wt-perf binary to run them and provides its
//! path via `CARGO_BIN_EXE_wt-perf` β€” this is what triggers the binary build
//! under a workspace `cargo test` (see Cargo.toml's header comment).
use std::io::Write;
-use std::process::{Command, Stdio};
+use std::process::{Command, Output, Stdio};
fn wt_perf_bin() -> &'static str {
env!("CARGO_BIN_EXE_wt-perf")
}
+fn run_wt_perf(args: &[&str]) -> Output {
+ Command::new(wt_perf_bin())
+ .args(args)
+ .output()
+ .expect("Failed to run wt-perf")
+}
+
+#[test]
+fn help_exposes_only_canonical_operations() {
+ let output = run_wt_perf(&["--help"]);
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+
+ for subcommand in ["setup", "trace", "timeline"] {
+ assert!(
+ stdout.contains(subcommand),
+ "help must list {subcommand}:\n{stdout}"
+ );
+ }
+ assert!(
+ !stdout.contains("invalidate"),
+ "cold-cache investigation must route through timeline --cold:\n{stdout}"
+ );
+}
+
+#[test]
+fn setup_help_exposes_the_semantic_fixture_catalog() {
+ let output = run_wt_perf(&["setup", "--help"]);
+ assert!(output.status.success());
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ assert!(
+ stdout.contains("--path <PATH>"),
+ "setup must require an explicit destination:\n{stdout}"
+ );
+
+ for subcommand in [
+ "typical",
+ "minimal",
+ "synthetic-divergence",
+ "large-repository",
+ "mixed",
+ "prune",
+ "large-repository-prune",
+ ] {
+ assert!(
+ stdout.contains(subcommand),
+ "setup help must list {subcommand}:\n{stdout}"
+ );
+ }
+ for removed in [
+ "large-repository-worktrees",
+ "large-repository-history-spread",
+ "picker-test",
+ ] {
+ assert!(
+ !stdout.contains(removed),
+ "setup help must not retain obsolete recipe {removed}:\n{stdout}"
+ );
+ }
+}
+
+#[test]
+fn setup_validation_does_not_acquire_large_repository_fixtures() {
+ let output = run_wt_perf(&["setup", "minimal", "0", "0"]);
+ assert!(!output.status.success());
+ assert!(
+ String::from_utf8_lossy(&output.stderr).contains("Missing required --path"),
+ "setup must enforce an explicit destination:\n{}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+
+ let path = tempfile::tempdir().expect("Failed to create temp dir");
+ let output = run_wt_perf(&[
+ "setup",
+ "large-repository-prune",
+ "12",
+ "24",
+ "--path",
+ path.path().to_str().unwrap(),
+ ]);
+ assert!(!output.status.success());
+ assert!(String::from_utf8_lossy(&output.stderr).contains("Destination already exists"));
+}
+
+#[test]
+fn setup_builds_a_semantic_recipe_at_an_explicit_path() {
+ let root = tempfile::tempdir().expect("Failed to create temp dir");
+ let repo = root.path().join("minimal-fixture");
+ let output = run_wt_perf(&[
+ "setup",
+ "minimal",
+ "0",
+ "0",
+ "--path",
+ repo.to_str().unwrap(),
+ ]);
+ assert!(
+ output.status.success(),
+ "setup failed:\n{}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("wt-perf timeline --cold -- -C"),
+ "setup must direct cold investigation through timeline --cold:\n{stderr}"
+ );
+ assert!(
+ !stderr.contains("wt-perf invalidate"),
+ "setup must not advertise the removed standalone command:\n{stderr}"
+ );
+ assert!(repo.join(".git").is_dir(), "setup must create a git repo");
+
+ let branches = Command::new("git")
+ .args([
+ "-C",
+ repo.to_str().unwrap(),
+ "branch",
+ "--format=%(refname:short)",
+ ])
+ .output()
+ .expect("Failed to inspect built fixture");
+ assert!(branches.status.success());
+ assert_eq!(String::from_utf8_lossy(&branches.stdout), "main\n");
+}
+
+#[test]
+fn setup_never_mutates_an_existing_destination() {
+ let root = tempfile::tempdir().expect("Failed to create temp dir");
+ let destination = root.path().join("existing");
+ std::fs::create_dir(&destination).expect("Failed to create destination");
+ let sentinel = destination.join("sentinel");
+ std::fs::write(&sentinel, "keep").expect("Failed to write sentinel");
+
+ for path in [
+ destination.clone(),
+ root.path().join("missing-parent/../existing"),
+ ] {
+ let output = run_wt_perf(&[
+ "setup",
+ "minimal",
+ "0",
+ "1",
+ "--path",
+ path.to_str().unwrap(),
+ ]);
+ assert!(
+ !output.status.success(),
+ "setup unexpectedly accepted {path:?}"
+ );
+ assert_eq!(std::fs::read_to_string(&sentinel).unwrap(), "keep");
+ assert!(!destination.join(".git").exists());
+ }
+}
+
/// Test that the binary produces Chrome Trace Format JSON for sample trace input.
#[test]
fn test_wt_perf_trace_from_stdin() {
@@ -70,10 +224,7 @@ fn test_wt_perf_trace_from_stdin() {
#[test]
fn test_wt_perf_trace_no_input_shows_usage() {
// Test by passing a non-existent file
- let output = Command::new(wt_perf_bin())
- .args(["trace", "/nonexistent/path/to/file.log"])
- .output()
- .expect("Failed to run wt-perf");
+ let output = run_wt_perf(&["trace", "/nonexistent/path/to/file.log"]);
assert!(
!output.status.success(),