Repository navigation
perf(cargo): each worktree builds into its own slot of the shared target - #316
Conversation
Worktrees of one workspace get the same build hashes in a shared target dir, so the lock marked a worktree's sources as changed whenever another worktree had built last: every switch between worktrees rebuilt the workspace crates. Each worktree now builds them into one of six build slots, next to the dependencies all share. Cargo names a workspace member's artifacts after the path of RUSTC_WORKSPACE_WRAPPER, so every slot has a pass-through wrapper at its own path. Clippy sets that variable itself and gets the slot as a --cfg, which it records with its result. Sources are marked only when a worktree takes a slot, and for commands that cannot use one.
|
bstack-judge: PASS+NOTES tier=1 sha=0784365b6cdbc1be8bba9fd940cfec6fc1936194 PR 316 (head 0784365, checked out detached in a temporary worktree of the local bstack clone, since removed) passes. I found no blocking defect and one non-blocking note. Criteria, taken from the PR's Request and "What changed", and proven by running
Weakened checks: the two removed tests are replaced by equivalents that run the old behaviour through Attack hypotheses I reproduced on fixtures:
Findings: F1 does not block. It needs more concurrent no-lock [{"id":"F1","title":"Slot takeover during another worktree's in-flight lock-free cargo run can leave the new owner running the old owner's app (needs more concurrent run-worktrees than slots; shared debug/<name> path is already named in Scope)","reproduction":"BSTACK_CARGO_SLOTS=2, four worktrees with src/main.rs printing their number, CARGO_TARGET_DIR shared, run `node plugins/bstack/scripts/cargo-lock.mjs cargo run --offline --quiet` in all four at once","base":"not run","head":"fail","blocks":"no","files":["plugins/bstack/scripts/cargo-lock.mjs"]}] |
Request
From the owner, after a review of two days of agent sessions on a Rust workspace: "ja lav punkt 1", where point 1 was: give every worktree its own files for the app code in the shared build dir, so a worktree does not rebuild the app code each time another one has built.
Why
Worktrees of one workspace get the same build hashes in a shared target dir. The lock therefore marked a worktree's sources as changed whenever another worktree had built last, so with two or three agents taking turns, nearly every cargo command rebuilt the workspace crates under the lock. On the workspace this was found on (two crates, about 68,000 lines) that is about 105 s per turn, and agents queued behind it for up to 44 minutes.
What changed
RUSTC_WORKSPACE_WRAPPERtoo; every slot has a pass-through wrapper at its own path, compiled once per target dir withrustc.cargo clippysets that variable itself, so it gets the slot as--cfg=bstack_slot_<n>. Clippy records its arguments with its result, so another slot's result is never reused, and the test artifacts are left alone.rustc.Removed tests
risk-tierreports "test removed" for two tests that asserted the old behaviour, which is what this change replaces:cargo rustdoc).Five tests are new: own build per worktree with nothing rebuilt on return, slot takeover,
cargo runin a slot, clippy per worktree, and the two above in their new form.Scope
Not done: running tests without the lock (the built app at
debug/<name>is still one path for all worktrees), and a slot per worktree for clippy's own artifacts (clippy re-checks the workspace crates when worktrees take turns).Blast radius
Every repo that runs cargo through
cargo-lock.mjs. The first build of each worktree after the update rebuilds its workspace crates once into its slot. Disk: up to six sets of workspace artifacts per target dir.BSTACK_CARGO_SLOTSchanges the number.Verification
node --test "tests/*.test.mjs": 899 tests, 873 pass, 0 fail, 26 skipped.node tools/check-plugin.mjs: ok.cargo-lock.mjs),cargo test --workspace --locked --no-run:11 passed.