Skip to content

fix: restore dedicated copy thread pool to avoid CPU saturation - #1905

Merged
max-sixty merged 1 commit into
mainfrom
copy-ignored
Apr 4, 2026
Merged

max-sixty merged 1 commit into
mainfrom
copy-ignored

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

#1901 removed the dedicated copy pool, so copy_dir_recursive started using the global rayon pool (2× CPU cores, tuned for network I/O). This caused ~1000% CPU on copy-heavy operations like wt step copy-ignored with large target/ directories.

Restores a 4-thread LazyLock pool internal to copy_dir_recursive — no public API change needed. The pool is the same approach benchmarked in #1721 (performance peaks at 2–4 threads for disk I/O).

This was written by Claude Code on behalf of @max-sixty

The global rayon pool (2× CPU cores, tuned for network I/O in `wt list`)
was being used for copy-ignored operations after #1901 removed the
dedicated pool. This caused ~1000% CPU usage on copy-heavy operations
that should be background work.

Restores a 4-thread `LazyLock` pool internal to `copy_dir_recursive`.
The public API is unchanged — no `in_copy_pool` wrapper needed since the
pool entry happens inside `copy_dir_recursive` itself.

Co-authored-by: Claude <[email protected]>
@max-sixty
max-sixty merged commit 1af3e14 into main Apr 4, 2026
24 checks passed
@max-sixty
max-sixty deleted the copy-ignored branch April 4, 2026 04:41
max-sixty pushed a commit that referenced this pull request Apr 4, 2026
## Problem

CI on `main` failed on Windows with a stack overflow in
`test_copy_ignored_many_directories_no_emfile`:

```
thread '<unknown>' (2316) has overflowed its stack
```

The rayon worker in the copy thread pool inherits the platform default
stack size. On Linux/macOS this is ~8 MiB, but on Windows it is only
~2 MiB, which is not enough for concurrent `reflink_or_copy` work over
200 directories of ignored files.

The failing run (23987711021) sits on a commit (#1910) that doesn't
touch the copy path — this is a latent Windows-specific issue in the
dedicated copy pool introduced in #1905.

## Solution

Set an explicit 8 MiB `stack_size` on `COPY_POOL` so behaviour is
consistent across platforms. This matches the Unix default and is a
narrow, targeted fix at the place the problem is — the rayon pool used
exclusively for `copy_dir_recursive`.

## Testing

- `cargo test --test integration
test_copy_ignored_many_directories_no_emfile` passes locally (Linux).
- Full Windows CI re-run will exercise the large-scale concurrent copy
path.

---
Automated fix for [failed
run](https://github.com/max-sixty/worktrunk/actions/runs/23987711021)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants