Repository navigation
perf(picker): stage preview pre-compute and unify rayon pool - #2662
Merged
Merged
Conversation
The picker's preview pre-compute and `wt list`'s row pipeline were both fanning out git subprocesses on independent rayon pools (each 2× CPU). On an 8-core machine the OS saw ~32 concurrent threads racing for cores during the row-fill window, slowing the rows the user is actually watching. Two changes: 1. **Stage the preview fan-out by user-perceived priority.** At `on_skeleton`, fire the first item × all 4 modes (the user lands on row 0 and tab-cycles modes there) plus `WorkingTree` for items 1..N (the picker's initial tab — pre-warms j/k navigation). Defer the secondary modes and LLM summaries for items 1..N to a new `PickerProgressHandler::on_collect_complete` hook that fires after the row pipeline drains. The static Summary hint (no LLM) is filled for every row synchronously at skeleton time. 2. **Unify the picker's dedicated preview pool into the global rayon pool.** `PreviewOrchestrator` no longer owns a `ThreadPool`; spawns route through `rayon::spawn` / `rayon::spawn_fifo`. Workers prefer their local deques over the injector, so row tasks (submitted via `into_par_iter`) naturally take priority over preview tasks (submitted via the orchestrator) once row work begins. The `pending` counter machinery for `wait_for_idle` is independent of pool, so the dry-run path and tests are unchanged. Net effect: ~32 OS threads → ~16. Preview pre-compute still warms the user's most likely interactions during/before drain; secondary preview modes and LLM summaries land after drain without idling the pool unnecessarily. Tests cover the two-tier staging (`precompute_staging_tiers_match_design`), the no-skeleton / single-item edge cases (`on_collect_complete_is_no_op_when_no_rest_items`), and the existing log-refresh path. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
worktrunk-bot
approved these changes
May 10, 2026
4 tasks done
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
…ings (#2683) ## Summary `cargo bench --bench list` was failing ~30% of runs partway through fixture setup with errors like "fatal: unable to read tree", "invalid object ... for 'src/file_N.rs'", "unable to create temporary file", or "failed to insert into database". Root cause: git's auto-maintenance (`gc.auto` + `maintenance.auto`) fires during the 500-commit fixture-build loop and races the foreground `git add` / `git commit`. Partial-failure repos contained 5-6 pack files plus a `tmp_pack_*` — smoking gun for a detached pack/prune in flight. `create_repo_at` now silences both auto-maintenance knobs after `git init`, and runs one explicit `git gc` at the end after all commits, branches, and worktrees are in place. The result: 10/10 sequential `wt-perf setup typical-8` builds pass, and fixtures land in a packed shape (one packfile + commit-graph, zero loose objects) that matches day-N user repos rather than the loose-object cold-clone shape they had before. ## Thread-count follow-up to #2662 Using the stabilized benches to answer the question in #2662's "Follow-ups": should `rayon_thread_count` bump from 2× CPU now that we have one pool instead of two? Swept `RAYON_NUM_THREADS` across {0.5×, 1×, 1.5×, 2×, 3×, 4×, 6×} on an 18-CPU machine against `divergent_branches/warm` (branch-heavy) and `worktree_scaling/warm/8` (worktree-heavy). 3× CPU was at or within noise of the per-workload optimum on both; 2× trailed by 0–5% (divergent 259ms vs 257ms with overlapping CIs; worktree 86.6ms vs 82.4ms, ~5% gap). 4× regressed on branch-heavy workloads. Stayed at 2×: the win is small in absolute terms (≤ 5ms) and 2× has been validated in production on hardware we haven't benchmarked. Docstring on `rayon_thread_count` records the test and the reasoning so the next person who asks doesn't have to redo the experiment. ## Test plan - [x] `cargo run -- hook pre-merge --yes` — 3547 tests pass - [x] `wt-perf setup typical-8 --persist` × 10 sequential — no failures (pre-fix: ~30% failure rate) - [x] `cargo bench --bench list divergent_branches/warm` — completes, packed shape (1 pack, 0 loose) - [x] `cargo bench --bench list worktree_scaling/warm/8` — completes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
6 tasks done
max-sixty
added a commit
that referenced
this pull request
May 11, 2026
## Summary - Adds `picker_preview` benchmark group measuring "process spawn → all preview tasks drained" for `wt switch`'s interactive picker. - Introduces `WORKTRUNK_PREVIEW_BENCH=1`, an early-exit gate inside `handle_picker` that runs the full prelude (collect, speculative spawn, skeleton, initial + deferred precompute, `orchestrator.wait_for_idle()`) and returns before skim launches or any JSON / stderr I/O. Shares the dry-run path; behavior with the env var unset is unchanged. - Closes the coverage gap behind #2662 / #2683 / #2685 / #2704, which were tuned against `wt list` as a proxy because no direct picker measurement existed. ## Why this measurement Picker submits one preview-compute task per row to the global rayon pool. The user-visible quantity to optimize is the responsiveness window between picker launch and "all previews ready" (j/k navigation hits cached content). Option 1 from the task — headless wall clock to drain — is the cleanest measurable proxy and avoids the PTY route, which hits the documented nextest/SIGTTOU pain on `shell-integration-tests`. PTY-driven first-interactive-ready can be a follow-up. ## Variants - `picker_preview/warm/typical-8` - `picker_preview/cold/typical-8` Cold uses `BatchSize::PerIteration` (not `SmallInput`): `SmallInput` calls `setup` for an entire batch up front and then runs timed routines back-to-back, so only the first iter in each batch is genuinely cold — the rest hit a freshly populated `.git/wt/cache/`. `PerIteration` invalidates immediately before every measured iteration; setup is far cheaper than `wt switch`, so per-iter `Instant::now` doesn't dominate. `sample_size(10)` + `measurement_time(35s)` per #2685's lead — slow benches don't benefit from the default 30 samples. `cfg(unix)`-gated with a no-op `main` on Windows; the picker is Unix-only and `wt switch` (no args) hits the unavailable path before the env var is consulted. ## Sample run ``` picker_preview/warm/typical-8 time: [185.62 ms 191.72 ms 200.77 ms] picker_preview/cold/typical-8 time: [209.34 ms 226.23 ms 239.29 ms] ``` ## Test plan - [x] `cargo bench --bench picker_preview` runs cleanly on both variants - [x] `cargo run -- hook pre-merge --yes` — 3667 tests pass - [x] New `test_picker_preview_bench_produces_no_output` asserts `WORKTRUNK_PREVIEW_BENCH=1` keeps stdout/stderr empty (covers the env-gated branch, locks the no-I/O contract) - [x] Smoke test: `wt switch` with `WORKTRUNK_PREVIEW_BENCH` unset still hits the TTY error path (user-visible behavior unchanged) - [x] Smoke test: `WORKTRUNK_PICKER_DRY_RUN=1` still emits the cache JSON dump (regression check) - [x] `/review-codex` pass clean after iterating on three findings (packed-refs fix already on `main` via #2697 once branch was rebased; `BatchSize::PerIteration` for true per-iter invalidation; `cfg(unix)` gate for Windows) > _This was written by Claude Code on behalf of Maximilian Roos_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The picker's preview pre-compute and
wt list's row pipeline were each fanning out git subprocesses on their own 2× CPU rayon pool. On an 8-core machine the OS saw ~32 concurrent threads racing for cores during the row-fill window, slowing the rows the user is actively watching.This PR makes two changes that compose:
1. Stage preview pre-compute by user-perceived priority
At
on_skeleton(skeleton render), the orchestrator fires:WorkingTree/Log/BranchDiff/UpstreamDiff) — the user lands on row 0 and frequently tab-cycles modes there.WorkingTreeonly — the picker's initial tab. Pre-warms quick j/k navigation without paying the 4-mode bulk cost per row.A new
PickerProgressHandler::on_collect_completehook (default no-op) fires aftercollect()'s drain finishes. The picker uses it to spawn the deferred tier:Log,BranchDiff,UpstreamDiff}2. Unify the picker's preview pool into the global rayon pool
PreviewOrchestratorno longer owns a dedicatedThreadPool.self.pool.spawn(...)→rayon::spawn(...); the log-refreshpool.spawn_fifo(...)→rayon::spawn_fifo(...). Workers prefer their local deques (whereinto_par_iter's row tasks land) over the global injector (where the orchestrator's preview tasks land), so row tasks naturally take priority during drain — no explicit gating needed beyond submission order.Net effect on an 8-core machine: ~32 OS threads → ~16. The
pendingcounter forwait_for_idleis pool-independent, so the dry-run path and tests are unchanged.Where to start reading
preview_orchestrator.rs— the orchestrator changes (pool removal + tiered spawn methods + theINITIAL_MODE/SECONDARY_MODESconsts).progressive_handler.rs— theon_skeleton/on_collect_completewiring + the newdeferred_items: OnceLock<Vec<Arc<ListItem>>>field that bridges the two hooks.collect/mod.rs— the new trait method + its single call site near the end ofcollect().Tests
precompute_staging_tiers_match_design— asserts the tier boundary explicitly (first item × all 4 modes + items 1..N ×WorkingTreecached afteron_skeleton; secondary modes only afteron_collect_complete).on_collect_complete_is_no_op_when_no_rest_items— covers the no-skeleton early-return path and the single-item case.log_disk_hit_triggers_background_refreshandnon_log_modes_do_not_trigger_log_refreshcontinue to validate thespawn_fifoordering through the unified pool.3542 tests pass via
wt hook pre-merge --yes; clippy clean.Follow-ups
The follow-up to evaluate:
rayon_thread_count()returns 2× CPU. Pre-unification we had two independent 2× CPU pools (4× CPU total OS threads); post-unification we're at 2× CPU total. For a workload that's mostly git subprocesses blocked on pipe reads + occasional network calls, 4× CPU may be the right size. Worth benchmarking withRAYON_NUM_THREADSoverrides oncargo bench --bench list scaling/warmandwt-perf timelinebefore deciding.