Skip to content

fix(worktree): restore sparse checkout without per-poll git subprocesses - #1316

Merged
Jinwoo-H merged 5 commits into
mainfrom
fix-sparse-checkout-perf
May 1, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
fix-sparse-checkout-perf

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Re-lands the sparse checkout feature from #1131 and fixes the performance regression that forced its revert in #1290.

  • Commits 1–4: original Add sparse checkout worktree creation #1131 re-applied on top of current main (previously reviewed)
  • Commit 5 (fix(worktree): detect sparse checkout via fs.stat instead of git subprocess): the actual fix, isolated as a standalone diff so reviewers can see exactly what changed

Root cause of the lag

listWorktrees() in src/main/git/worktree.ts ran detectSparseCheckout(worktree.path) for every non-bare, non-sparse worktree on every call. That detection was implemented as a git sparse-checkout list subprocess — so the call multiplied 1 git process into 1 + N git processes per invocation (N = non-bare worktrees).

listWorktrees is on the hot path:

  • useGitStatusPolling calls fetchWorktrees(activeRepoId) every 3 seconds while the window is focused (src/renderer/src/components/right-sidebar/useGitStatusPolling.ts:8,94)
  • fetchAllWorktrees fans out fetchWorktrees over every repo in parallel on startup and on repo-count changes

With multiple repos × multiple worktrees, this produced a continuous stream of git subprocess spawns on the main process every 3s. Each macOS git spawn is ~30–100ms of fork/exec + git startup — enough to visibly saturate main-process CPU and delay IPC to the renderer. The symptom "only laggy when the Orca window is focused" matches the document.hasFocus() gate on the poll.

Remote repos were unaffected because the relay's listWorktrees (src/relay/git-handler.ts:287-296) does not carry the sparse probe — consistent with the revert PR's observation that the issue was local-only.

Fix

detectSparseCheckout now does a single fs.stat on <gitdir>/info/sparse-checkout, reusing the existing resolveGitDir helper (promoted to an export in status.ts) so linked worktrees correctly resolve to their .git/worktrees/<name> directory. Semantics are preserved — Git writes that file when sparse checkout is enabled for the worktree and does not write it otherwise, which is the same truthiness the old sparse-checkout list stdout check was asserting.

No subprocess, one syscall, no new state.

The updated unit test asserts the absence of git sparse-checkout list in the call list, so the regression can't silently come back.

Verification

  • pnpm run typecheck — clean
  • pnpm run lint — 0 warnings, 0 errors
  • Sparse/worktree test scope (src/main/git, src/main/ipc/worktrees.test.ts, src/main/ipc/repos-sparse-presets.test.ts) — 125 passed, 0 failed

Test plan

  • Build a local mac arm64 DMG from this branch; confirm app is responsive with multiple repos and worktrees open
  • Create a sparse worktree via the composer; confirm the "sparse" badge appears on the worktree card
  • Create a normal (non-sparse) worktree; confirm no sparse badge appears and no regression in creation/removal flow
  • Confirm sparse detection still works after force-quitting and relaunching the app (file-based state survives restart)
  • Spot-check Activity Monitor / process list during idle polling — should see a single git worktree list per cycle, not a burst of git sparse-checkout list processes

Made with Orca 🐋

colinchambachan and others added 5 commits May 1, 2026 15:19
- Use Set-based comparison for sparse preset matching (order-independent)
- Replace JSON.stringify with arraysShallowEqual for worktree comparison
- Improve detectSparseCheckout to use sparse-checkout list (per-worktree)
- Surface cleanup failure context in addSparseWorktree error message
- Move sparse checkout UI to bottom of advanced options
- Remove unused src/shared/sparse-paths.ts (dead code from rebase)
- Fix build-relay.mjs ROOT path after scripts/ → config/scripts/ move

Co-authored-by: Orca <help@stably.ai>
…rocess

listWorktrees runs on every 3s git-status poll and on every worktree
refresh. The original sparse-checkout detection in #1131 spawned
`git sparse-checkout list` per non-bare worktree per call, so a user
with N worktrees paid 1+N git processes every poll. That regressed
main-thread responsiveness enough to require a full revert in #1290.

Replace the subprocess with a single fs.stat on the per-worktree
`info/sparse-checkout` config file, reached via the existing
resolveGitDir helper so linked worktrees resolve to their real
`.git/worktrees/<name>` directory. Same truthiness semantics, orders of
magnitude cheaper, no new state.

Co-authored-by: Orca <help@stably.ai>
@Jinwoo-H
Jinwoo-H merged commit bbd77c2 into main May 1, 2026
3 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix-sparse-checkout-perf branch May 1, 2026 20:25
mralexsaavedra pushed a commit to mralexsaavedra/orca that referenced this pull request May 2, 2026
…ses (stablyai#1316)

Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Colin <colin.chambachan@gmail.com>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ses (stablyai#1316)

Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Colin <colin.chambachan@gmail.com>
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