copy-ignored speed
@worktrunk-bot how do we do relative to this tweet?
The tweet describes three challenges with copying gitignored files across worktrees:
- Build cache loss —
wt step copy-ignoredsolves this directly. It's designed for exactly this use case. - Reflink /
cp -c— worktrunk usesreflink_copy::reflink_or_copy(), which does per-file COW on APFS (macOS), Btrfs, and XFS. For a 14GBtarget/directory, this takes ~20s vs ~2m for a full copy. - Deep-walk + parallelization + fd exhaustion — this is where there's room to improve:
What we do well:
git ls-files --ignored --directoryavoids deep-walking into directories liketarget/— it reportstarget/as a single entry, and we clone the whole tree recursively- Reflink means no actual data copying, just metadata ops
Where the tweet identifies gaps we have:
- No parallelization — the top-level copy loop (
step_commands.rs:725) is sequential. For repos with many top-level gitignored entries (e.g.,target/,node_modules/,.cache/, etc.), parallel entry copying could help. Insidecopy_dir_recursivethe walk is also sequential. - No fd management — we don't limit concurrent open file descriptors. The sequential approach avoids fd exhaustion by accident, but a parallel version would need to respect
ulimit -n(256 on macOS by default, as the tweet notes).
Potential improvement: Parallelizing the recursive directory walk with a bounded thread/task pool (e.g., rayon or crossbeam with a semaphore for fd limits) could meaningfully speed up large copies. The top-level entries are already independent, so they're trivially parallelizable.
TL;DR: worktrunk already handles challenges 1 and 2 from the tweet. Challenge 3 (parallel walk with fd management) is a real optimization opportunity — the current implementation is sequential.
how does the parallelization compare to the approach we had at one point (for just a moment), which had the downside of locking up the Mac (and I later found was not recommended)
That was the atomic clonefile() on directories approach from #602 — macOS/APFS can clone an entire directory tree as a single O(1) metadata operation via the clonefile() syscall, which was ~12-15x faster than file-by-file copying.
The problem was that it saturated disk I/O (~45K ops/sec), blocking interactive processes like shell startup — that's the "locking up the Mac" you experienced. Apple's own docs explicitly discourage it for large hierarchies. It was reverted in #640 to per-file reflink, which is slower but keeps the system responsive.
The parallelization the tweet describes is a middle ground between those two extremes:
| Approach | Speed | Responsiveness | fd pressure |
|---|---|---|---|
| Sequential per-file reflink (current) | Baseline | Great | Low |
| Parallel per-file reflink (tweet's idea) | ~2-4x faster | Good (tunable) | Needs management |
Atomic directory clonefile() (#602) |
~12-15x faster | Bad (saturates I/O) | N/A |
A bounded thread pool (e.g., rayon with a semaphore) would give us meaningful speedup without the I/O saturation problem — we control concurrency instead of handing the entire tree to the kernel in one shot. The tweet's point about fd limits (256 default on macOS) is the main constraint to respect.
ok, draft a PR that uses a rayon pool to run a few threads
also draft a PR to add a command that would warm the cache, if that's an atomic piece of work / step func
Drafted both PRs:
-
#1721 —
perf: parallelize copy-ignored with rayon— Parallelizes both the top-level entry loop and the recursive directory walk usinginto_par_iter().try_for_each(). Uses the existing global rayon pool (max 8 threads). No fd management needed since the bounded pool limits concurrency naturally. -
#1722 —
feat: add wt step warm as shorthand for copy-ignored— Thin wrapper that always copies from primary to current worktree. Omits--from/--to(usecopy-ignoreddirectly for custom paths). Includes hook configuration example in the help text.