Repository navigation
refactor(wt-perf): cache fixtures in the platform cache dir, not /tmp or target/ - #3542
Conversation
… or target/ `wt-perf setup` fixtures defaulted to a fixed name under `std::env::temp_dir()`, and the expensive real-repo fixtures lived under `target/bench-repos/`. Both are the wrong home for a reused fixture: - A fixed name in a shared `/tmp` (Linux) collides across users — the sticky bit makes the destructive setup's `remove_dir_all` panic for a second user — and is a predictable-path/TOCTOU hazard. systemd-tmpfiles can also reap a cold `.git/objects/pack/*.pack` at 10 days mid-use on `noatime` mounts. On macOS `temp_dir()` resolves to `/var/folders/.../T`, so the docs' `/tmp/wt-perf-*` paths were already wrong there. - `target/` is per-worktree (worktrees don't share it) and wiped by `cargo clean`, so the ~15 GiB rust clone was re-cloned per worktree. Route both through `wt_perf_cache_dir()` — `$WT_PERF_CACHE_DIR` or the platform cache dir (`~/.cache/wt-perf`, `~/Library/Caches/wt-perf`): per-user (no collision), stable and discoverable (`-C <path>` and doc references still work), shared across worktrees (clone once per machine), and surviving `cargo clean`. In-process throwaway fixtures keep using `tempfile::TempDir`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
Reviewing as a draft — flagging anything that looks worth a quick fix. Mark ready for a full review.
Clean refactor; the rationale in the description is solid and the doc migration is complete (no stale target/bench-repos or /tmp/wt-perf-* references remain, and the in-process tempfile::TempDir fixtures are correctly left alone). Two low-severity notes inline.
Use `etcetera::choose_base_strategy().cache_dir()` instead of `dirs::cache_dir()`, so the fixture cache is `~/.cache/wt-perf` on both Linux and macOS — matching worktrunk's own base-dir convention (`src/config/user/path.rs` resolves user config through the same XDG-on-macOS strategy). `dirs::cache_dir()` would place it under `~/Library/Caches` on macOS instead. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address two footguns tend flagged in review:
- Treat an empty `WT_PERF_CACHE_DIR=` as unset. `var_os` returns `Some("")` for
an exported-but-empty var, which would give an empty cache root — so
`setup <config>` would `remove_dir_all` a *relative* `<config>` in the cwd
instead of a dir under the cache.
- Pin the benchmarks workflow's fixture cache to `WT_PERF_CACHE_DIR` and
reference the same var from the `actions/cache` path, so the cached path and
the path wt-perf writes can't drift. wt-perf otherwise computes the root from
the XDG cache dir, which honors `$XDG_CACHE_HOME` — a future runner setting it
would silently re-clone the ~15 GiB rust fixture every run.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The lint check is failing on a real (deterministic) formatting nit from this PR: the new etcetera import in tests/helpers/wt-perf/src/lib.rs is placed after the std:: imports, but rustfmt wants it sorted alphabetically before them. CI's own diff shows exactly this reorder. Inline suggestion below applies it.
The plan check failure is unrelated — a transient crates.io download blip (download of cl/ap/clap failed — curl failed); it'll pass on rerun.
Otherwise this is a clean refactor: routing the cache through choose_base_strategy().cache_dir() now mirrors worktrunk's own base-dir strategy in src/config/user/path.rs (same etcetera 0.11, XDG-on-macOS convention), and the two prior draft-review concerns (empty WT_PERF_CACHE_DIR, CI cache-path drift) are both resolved.
The lint check runs cargo fmt --check, which sorts `etcetera` alphabetically ahead of the `std::` imports. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… dir (#3547) ## What Move every `wt-perf` on-disk fixture out of the per-user cache dir and under the cargo target dir at `<target>/wt-perf/`, resolved by a renamed `wt_perf_fixture_dir()`: - `setup <config>` fixtures → `<target>/wt-perf/<config>` (was `~/.cache/wt-perf/<config>`). - The rust-lang/rust clone and `prune-real` fixtures → `<target>/wt-perf/bench-repos/` (was `~/.cache/wt-perf/bench-repos/`). - `wt_perf_cache_dir()` → `wt_perf_fixture_dir()`. The target dir is derived from the **running executable's own path** (it lives inside whichever dir cargo built into — `<target>/debug/wt-perf`, `<target>/release/deps/<bench>`), so it honors `CARGO_TARGET_DIR`, a config-file `build.target-dir`, and cargo-llvm-cov's `target/llvm-cov-target/` — none of which a bare `CARGO_TARGET_DIR` env read covers. Falls back to `<workspace>/target` if the binary isn't under a recognizable profile dir. The `etcetera` dependency is dropped. - The `WT_PERF_CACHE_DIR` env override (and the empty-value guard it required) is removed; the benchmarks workflow now caches the deterministic `target/wt-perf/bench-repos` path directly. - In-process throwaway fixtures (`create_repo`) are unchanged — they keep using `tempfile::TempDir`. This reverses the location decision from #3542, which had moved these into `~/.cache/wt-perf`. ## Why `target/` is the conventional home for build/test-generated artifacts — gitignored, reaped by `cargo clean`, and already where criterion writes (`target/criterion`). Keeping every wt-perf fixture there gives one predictable location under the repo that `cargo clean` fully resets. Deriving the target dir from the running binary (rather than assuming `<workspace>/target`) keeps that property intact even when the target dir is relocated. ## Tradeoff (accepted) `target/` is **not** shared across git worktrees (worktrees don't share it) and is wiped by `cargo clean`. So the ~15 GiB `prune-real` rust clone re-clones per worktree and after every `cargo clean` — the cost #3542 avoided by using the cache dir. This is deliberate and documented on `wt_perf_fixture_dir`; it's cheap for the synthetic `setup` fixtures, which rebuild in seconds. ## Testing - `cargo build -p wt-perf --all-targets`, `cargo test -p wt-perf` — clean. - New unit test `target_dir_from_exe_finds_cargo_target` covers the resolution logic (relocated `CARGO_TARGET_DIR`, bench binary under `release/deps/`, cargo-llvm-cov's nested target, closest-profile-wins, and the outside-any-target fallback). - `pre-commit run --all-files` (fmt, clippy, yaml, typos, cargo-lock, custom hooks) — clean. - Smoke-tested end-to-end: `setup branches-2` lands at `<worktree>/target/wt-perf/branches-2` and writes nothing to `~/.cache/`; a copy of the binary run from a fake `<dir>/debug/wt-perf` correctly resolves fixtures to `<dir>/wt-perf/`, proving a relocated target dir is honored. > _This was written by Claude Code on behalf of Maximilian_ --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
What
Move
wt-perf's benchmark/debug fixture repos out ofstd::env::temp_dir()andtarget/bench-repos/into the per-user cache dir, resolved by a newwt_perf_cache_dir():$WT_PERF_CACHE_DIRif set, else<cache>/wt-perfviaetcetera::choose_base_strategy().cache_dir()—~/.cache/wt-perf(or$XDG_CACHE_HOME/wt-perf) on Linux and macOS. This matches worktrunk's own base-dir convention (src/config/user/path.rsresolves user config through the same XDG-on-macOS strategy).setup <config>fixtures →<cache>/<config>(wastemp_dir()/wt-perf-<config>).--pathstill overrides.prune-real, the rust-lang/rust clone) →<cache>/bench-repos/(wastarget/bench-repos/).create_repo) are unchanged — they keep usingtempfile::TempDir.Why
Both old homes were wrong for a reused fixture (these are given stable names, persist between runs, and are referenced from docs and
-C <path>— that's a cache, not a temp file):/tmp(Linux) collides across users:/tmpis sticky (1777), so a second user'ssetuphitsremove_dir_all().unwrap()on a dir they don't own →EPERM→ panic. It's also a predictable-path/TOCTOU hazard, andsystemd-tmpfilesreaps/tmpper-file at 10 days bymax(atime,mtime,ctime)— on anoatimemount an actively-read fixture still loses cold.git/objects/pack/*.packmid-use → silent git corruption.temp_dir()is already/var/folders/.../T(per-user,0700), so the docs'/tmp/wt-perf-*paths were simply wrong there.target/is per-worktree (git worktrees don't share it) and wiped bycargo clean, so the ~15 GiB rust clone was re-cloned per worktree — worst for the most expensive fixture, in a worktree-heavy workflow.The cache dir is per-user (no collision, no TOCTOU), stable and discoverable (docs/
-Creferences still work), shared across worktrees (clone once per machine), and survivescargo clean— matching sccache, cargo, rustup, Go, Bazel, and Hugging Face, which all place large reusable caches there rather than in/tmp.Migration notes
target/bench-repos/is no longer read). Existing fixtures can be dropped withrm -rf target/bench-repos..github/workflows/benchmarks.yamlsetsWT_PERF_CACHE_DIRand caches$WT_PERF_CACHE_DIR/bench-repos, so the cached path and the path wt-perf writes stay pinned together (no drift if a runner sets$XDG_CACHE_HOME); key unchanged.benches/CLAUDE.md,src/commands/CLAUDE.md) updated to the new paths, noting thatwt-perf setupprints the exact path.Testing
cargo build --workspace --all-targets,cargo clippy --workspace --all-targets --features shell-integration-tests -- -D warnings— clean.cargo test -p wt-perf— passes.~/.cache/wt-perf/…on macOS),$WT_PERF_CACHE_DIRoverride, and theprune-real --pathrejection (now names the resolved cache path).