Commit 67770e3
authored
fix(watcher): stop cross-worktree fan-out via shared commondir (#2971)
## Problem
Starting a new worktree task gets slower as the number of existing worktrees grows. Reported from a fresh machine (few worktrees) feeling dramatically faster than an older one with many worktrees.
Root cause: linked worktrees share the main repo's `.git` as their `commondir`, and each worktree's `watchRepo` recursively watches that commondir. So mutating *any* worktree's admin dir under `.git/worktrees/` — notably **creating a new worktree** (which writes `.git/worktrees/<name>/HEAD`) — woke *every* other worktree's watcher. Each wake fired a server-side branch re-check (a `git rev-parse` subprocess) and a renderer branch-query invalidation. With N worktrees, one git operation triggered ~N subprocesses + N invalidations, so the per-event cost grew linearly with worktree count — and creating a task is exactly the moment that writes to the shared `.git`.
## Changes
Exclude the `worktrees/` admin subtree (`**/worktrees/**`) from the git-dir watches in `WatcherService.watchRepo`.
- A worktree's own admin dir is still watched directly as its `gitDir` (rooted inside `worktrees/<name>`, where the pattern matches nothing), so its own HEAD changes are still observed.
- Shared refs (`refs/heads`, `packed-refs`) live outside `worktrees/`, so commits/branch changes still propagate to sibling worktrees as before.
- Only cross-worktree admin noise is dropped.
Note: the `ignore`-option mechanism is load-bearing here — it's relative to each watch root, so it suppresses the subtree only for the shared commondir watch and not for a worktree's own gitDir watch. Filtering by an absolute-path substring instead would wrongly drop a worktree's own HEAD events.
## How did you test this?
- Added `service.test.ts` covering the ignore wiring for both a linked worktree (commondir + own gitDir get the worktrees ignore; working tree keeps node_modules/.git ignores) and a non-worktree repo. Both pass via `vitest run src/services/watcher/service.test.ts`.
- `biome lint` clean on the watcher dir; `tsc` clean for the changed files (remaining repo typecheck errors are unbuilt sibling-package `dist/`, unrelated to this change).
## Automatic notifications
- [ ] Publish to changelog?
- [ ] Alert Sales and Marketing teams?
---
*Created with [PostHog](https://posthog.com?ref=pr) from a [Slack thread](https://posthog.slack.com/archives/C09G8Q32R6F/p1782718496987319?thread_ts=1782718496.987319&cid=C09G8Q32R6F)*1 parent a289096 commit 67770e3
2 files changed
Lines changed: 97 additions & 1 deletion
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
13 | 26 | | |
14 | 27 | | |
15 | 28 | | |
| |||
202 | 215 | | |
203 | 216 | | |
204 | 217 | | |
205 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
206 | 223 | | |
207 | 224 | | |
208 | 225 | | |
| |||
0 commit comments