Skip to content

fix(watch): space out overflow sweeps and cap background scans at two - #89

Merged
rocketraman merged 2 commits into
masterfrom
claude/gitvantage-performance-slow-1b66fa
Nov 17, 2026
Merged

rocketraman merged 2 commits into
masterfrom
claude/gitvantage-performance-slow-1b66fa

Conversation

@rocketraman

Copy link
Copy Markdown
Owner

Problem

After about 13 days running, 1.6.1 stalled the UI for 0.5–6.4s at a time. In the diagnostics log, stall length grows in step with the number of git launches during the stall: 11–15ms per launch (median 13, across 101 stalls). Every launch is a fork() of the app, and the UI thread stalls while the kernel copies it.

The bursts were full sweeps of all 42 repos, about 750 git launches each, 8 scans at a time. Inotify overflows set them off: 4 a minute while a coding session worked in a repo with 22 nested worktrees under .claude/. An overflow can't be traced to a repo, so each one rescans all of them. The 5-minute auto-refresh sweeps too.

Change

  • Spacing overflow sweeps: a full sweep now starts no sooner than 2 minutes after the previous one finished (WatchPolicy.FULL_RESCAN_MIN_INTERVAL_MS). Overflows in between merge into the pending sweep and can't postpone it. A repo that changes again still gets its own scan right away.
  • Background spawn cap: watcher rescans and auto-refresh go through their own limit of 2 instead of the shared 8. Their git launches then leave the UI time to draw, and user actions no longer queue behind them.

Not addressed

Restarting the app cut the stall to about 1.6ms per launch, but RSS was only about 20% smaller. Something besides process size makes forks more expensive the longer the app runs. That's still unexplained; this PR cuts how many launches there are rather than what each one costs.

Testing

  • New WatchFullRescanSpacing suite: 4 tests, all ran (checked in the result XML). Full suite: 295 tests, 0 failures.
  • The background limiter wiring isn't covered by a test. It hasn't been run long enough in a real build to show whether the stalls stay away.

Every git launch is a fork() of the app, and the UI thread stalls while
the kernel copies it. A field report (1.6.1, 42 repos, 13 days up) measured
11-15ms of UI stall per launch, and the stalls lasted up to 6.4s.

The bursts came from full sweeps. A coding session's .claude/ churn
overflowed inotify 4 times a minute, and each overflow rescanned every
repo: about 750 git launches each time, 8 scans in parallel.

Overflow sweeps now run at least 2 minutes apart. Overflows in between
merge into the pending sweep and can't postpone it. Watcher and
auto-refresh scans share a separate cap of 2 at a time, so their launches
leave the UI room to draw. User actions keep the cap of 8 and no longer
queue behind a background sweep.

Signed-off-by: Raman Gupta <rocketraman@gmail.com>
Background scans now run on Dispatchers.IO.limitedParallelism(2) instead
of taking permits from a semaphore.

RepoScanner.scan takes the dispatcher as a parameter. Wrapping the call
in withContext would not work: scan switches to Dispatchers.IO itself,
which would escape the limit. A scan blocks without suspending, so it
holds its slot from start to finish.

Signed-off-by: Raman Gupta <rocketraman@gmail.com>
@rocketraman
rocketraman merged commit b0e20ea into master Nov 17, 2026
2 checks passed
@rocketraman
rocketraman deleted the claude/gitvantage-performance-slow-1b66fa branch November 17, 2026 21:22
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