Skip to content

perf: load the worktree list without blocking the event loop - #350

Merged
kbwo merged 1 commit into
mainfrom
perf/async-worktree-list
Oct 27, 2026
Merged

kbwo merged 1 commit into
mainfrom
perf/async-worktree-list

Conversation

@kbwo

@kbwo kbwo commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Merge risk

Low. Only the way three existing git commands are spawned changes (synchronous execSync → the existing async execAsync); the commands and their parsing are unchanged. Unit tests, typecheck and lint pass, and the effect was measured in a pseudo-terminal.

Summary

  • getWorktreesEffect runs git worktree list --porcelain through execAsync, and the per-worktree git describe --all HEAD (detached HEAD only) runs in parallel.
  • getDefaultBranchEffect runs its three lookups (symbolic-ref, rev-parse main, rev-parse master) through execAsync.
  • The symbolic-ref test now asserts the exec call shape instead of the execSync one.

Problem

With many worktrees (about 100), returning from a session to the menu left the screen blank for 3–4 seconds. The menu is remounted on return and shows the cached list right away, but the synchronous git worktree list blocked the event loop, so Ink could not paint. The same moment starts the git status polling cycle; with those git processes running, the synchronous call took about 3.2–3.6 s instead of about 0.12–0.25 s right after startup. The same blank appears on main, so it is not caused by an earlier change. Using the async variant keeps the event loop free, so the cached list is painted immediately.

Verification

  • bun run typecheck, bun run lint, bun run test: pass.
  • Session → menu return with 101 worktrees, replayed through a terminal emulator (a fake claude that just sleeps, return key Ctrl+E), time until the list rows are on screen, rounds after the first:
    • main: 2.6–3.0 s
    • this branch: 79–116 ms

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kbwo
kbwo merged commit 4720468 into main Oct 27, 2026
1 check passed
@kbwo
kbwo deleted the perf/async-worktree-list branch October 27, 2026 23:37
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.

1 participant