perf(select): pre-compute preview tabs in background#935
Merged
Conversation
Add background pre-computation and caching for all preview modes (HEAD±, log, main…±, remote⇅). When the selector starts, a background thread computes previews for all worktrees while the user views the list. Tab switching is now near-instant once pre-computation completes. Changes: - Add PreviewCache with compound key (branch_name, mode) - Convert all render methods to static compute_* functions - Extract compute_diff_preview as shared helper - Add PREVIEW_WIDTH_PERCENT constant (consolidates 50% logic) - Derive Hash for PreviewMode to use as DashMap key Co-Authored-By: Claude <noreply@anthropic.com>
Cache raw git output without pager processing. Apply pager only when displaying cached results. This enables background pre-computation to produce the same output as foreground, making caching effective. - Replace run_git_diff_with_pager with pipe_through_pager - pipe_through_pager takes text input via stdin instead of running git - Apply pager in preview_for_mode for diff modes (1, 3, 4) - Graceful fallback returns original text on pager failure Co-Authored-By: Claude <noreply@anthropic.com>
Address Codex review findings: - Don't join writer thread before timeout loop (can hang if pipe fills) - Add wait() after kill() to reap zombie processes - Join reader thread on error paths to avoid thread leaks Co-Authored-By: Claude <noreply@anthropic.com>
Replace manual polling loop with wait_timeout::ChildExt::wait_timeout(). Removes ~15 lines of timeout/cleanup logic while preserving behavior. Co-Authored-By: Claude <noreply@anthropic.com>
Tests passthrough, transform, invalid command, and failing command paths. Co-Authored-By: Claude <noreply@anthropic.com>
- Move wait-timeout to regular deps (works cross-platform) - Simplify shell/utils.rs compinit probe timeout - Simplify shell_exec.rs command timeout Removes manual polling loops in favor of explicit wait_timeout() calls. Co-Authored-By: Claude <noreply@anthropic.com>
wait_timeout reaps the process, so wait_with_output() afterward would call wait() on an already-reaped child. Take stdout handle before wait_timeout and read it directly after process exits. Co-Authored-By: Claude <noreply@anthropic.com>
- shell/utils.rs: Use bytes + lossy decode instead of read_to_string to avoid turning invalid UTF-8 probe failures into Some(false) - pager.rs: Cache has_explicit_pager_config() result in OnceLock to avoid reloading user config on every preview render Co-Authored-By: Claude <noreply@anthropic.com>
Combine CACHED_PAGER and HAS_EXPLICIT_PAGER_CONFIG into one CachedPager struct. Both values are derived from the same user config check, so computing them together avoids redundant initialization. Co-Authored-By: Claude <noreply@anthropic.com>
Move --paging=never logic into cache initialization so the stored command is ready to use. This eliminates: - CachedPager struct and is_explicit field - has_explicit_pager_config() function - Runtime check on every pipe_through_pager call Co-Authored-By: Claude <noreply@anthropic.com>
Exercises the get_diff_pager() initialization code path to improve codecov/patch coverage. Co-Authored-By: Claude <noreply@anthropic.com>
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
wait-timeoutcrate across codebaseTab switching is now near-instant since cached results are served immediately.
Test plan
cargo test)wt selectshows instant tab switching between 1/2/3/4🤖 Generated with Claude Code