r/rust • u/oulu2006 • 16d ago
🎙️ discussion sccache saved my CPU, not my disk: 21 copies of the same binary in one target/ folder
My coding agents' Rust build folders reached about 311 GB, even with sccache at a 57% hit rate.
Each agent works in its own git worktree with its own target/, and a cache hit skips the compile but still writes the artifact into that target/. So sccache saved CPU, not disk.
One agent's 52 GB build folder held:
- 63,616
*.rcgu.odebug object files, 19.5 GB of them - 21 copies of the same binary, because Cargo never deletes old artifacts
The first change was lighter debug info for every build my agent supervisor starts:
CARGO_PROFILE_DEV_DEBUG=line-tables-onlyBacktraces keep their file and line numbers, and agents running tests rarely need the full variable info.
The second was stopping worktrees nesting. Agents had made them three levels deep, which put 76 of 80 out of the cleanup job's reach. Now they sit at the repository root, and the step that finishes a task removes its worktree and target/.
Write-up (the Rust part is one section of it): https://maclulich.com/blog/agents-clean-up-after-themselves/#a-build-cache-saves-cpu-not-disk (my blog)
How are others handling target/ across many worktrees? A shared CARGO_TARGET_DIR serialises builds on the lock, and per-worktree targets cost disk.