Skip to content

refactor: use static LazyLock pool for copy operations - #1894

Merged
max-sixty merged 6 commits into
mainfrom
refactor/copy-pool-lazylock
Apr 3, 2026
Merged

max-sixty merged 6 commits into
mainfrom
refactor/copy-pool-lazylock

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 3, 2026 •

Copy link
Copy Markdown
Owner

Replace per-call thread pool creation in copy_dir_recursive with a shared static COPY_POOL (LazyLock<ThreadPool>), following the established pattern used by HEAVY_OPS_SEMAPHORE and LLM_SEMAPHORE.

The EMFILE fix in #1864 used two coordinating pieces: a current_thread_index() check in copy_dir_recursive to detect ambient pool context, plus caller-side pool creation in step_copy_ignored. A single shared pool is simpler — nested install() calls are no-ops in rayon, so copy_dir_recursive works correctly both standalone and when called from in_copy_pool().

Also removes the hardcoded 4-thread cap (MAX_COPY_THREADS) in favor of rayon's default (num cores). The original benchmarks (#1721) tuned thread count for single-directory per-call pools, which is a different workload than the shared pool. Left a TODO to benchmark the shared pool specifically.

Follow-up to #1864.

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

max-sixty and others added 2 commits April 2, 2026 17:26
Replace per-call thread pool creation in copy_dir_recursive with a
shared static COPY_POOL (LazyLock<ThreadPool>), following the
established pattern used by HEAVY_OPS_SEMAPHORE and LLM_SEMAPHORE.

The previous EMFILE fix used two coordinating pieces: a
current_thread_index() check in copy_dir_recursive plus caller-side
pool creation in step_copy_ignored. A single shared pool is simpler
— nested install() calls are no-ops in rayon, so copy_dir_recursive
works correctly both standalone and when called from in_copy_pool().

Co-Authored-By: Claude <[email protected]>
Resolve conflicts: keep LazyLock pool approach over per-call pool
creation. Also tighten MAX_COPY_THREADS comment — remove unsubstantiated
"benchmarked on APFS and ext4" claim.

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 4 commits April 2, 2026 17:39
The value was empirically chosen via thread scaling benchmarks in #1721;
reference the issue instead of vague "benchmarked on APFS and ext4".

Co-Authored-By: Claude <[email protected]>
The #1721 benchmarks measured single-directory copies, not the shared
pool workload. Note the distinction while explaining why the value
still applies.

Co-Authored-By: Claude <[email protected]>
The hardcoded 4-thread cap was benchmarked for single-directory copies
(#1721) but the shared pool workload is different. Use rayon's default
(num cores) until we benchmark the shared pool specifically.

Co-Authored-By: Claude <[email protected]>
Comment thread src/copy.rs
/// spawning their own pool and exhausting OS file-descriptor limits on large
/// trees (EMFILE / "too many open files").
/// Uses the shared copy pool (capped at 4 threads) to avoid SSD I/O contention
/// from the larger global rayon pool.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pool no longer uses MAX_COPY_THREADS (4) — it uses rayon's default (num cores). This doc comment still says "capped at 4 threads".

Suggested change
/// from the larger global rayon pool.
/// Uses the shared copy pool to avoid contention from the larger global rayon
/// pool.

@max-sixty
max-sixty merged commit c0b93c6 into main Apr 3, 2026
26 checks passed
@max-sixty
max-sixty deleted the refactor/copy-pool-lazylock branch April 3, 2026 01:12
worktrunk-bot added a commit that referenced this pull request Apr 3, 2026
The pool was changed to use rayon's default (num cores) in #1894, but
the docstring on `copy_dir_recursive` still said "capped at 4 threads".

Co-Authored-By: Claude Opus 4.6 <[email protected]>
max-sixty added a commit that referenced this pull request Apr 3, 2026
The separate `COPY_POOL` (`LazyLock<rayon::ThreadPool>`) isolated copy
I/O from the global rayon pool. In practice there's no concurrent rayon
work during copies, so the isolation added complexity without benefit.
This removes the pool, `in_copy_pool()`, and the
`copy_dir_recursive_inner` indirection — copy operations now use the
global rayon pool directly.

Follows #1894 which introduced the static pool.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude <[email protected]>
natustx pushed a commit to natustx/worktrunk that referenced this pull request May 1, 2026
)

## Summary

- Add `-c system_prompt=''` to the Codex example command to skip the
default system prompt, reducing tokens and latency for commit message
generation

Follow-up from max-sixty#1295 — @max-sixty asked about using empty system prompts
for speed.

**opencode**: Does not currently support disabling the system prompt.
The system prompt is always injected, and even the plugin system has a
safety fallback that restores the original if emptied. There are open
feature requests
([max-sixty#1242](anomalyco/opencode#1242),
[max-sixty#1894](anomalyco/opencode#1894),
[#5005](anomalyco/opencode#5005)) but nothing
available yet.

**Codex**: Has an undocumented `system_prompt` config key that can be
overridden via `-c system_prompt=''`. There are feature requests for
dedicated `--system-prompt` flags
([#6023](openai/codex#6023),
[#11588](openai/codex#11588)) but not yet
merged.

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude Opus 4.6 <[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