Repository navigation
fix(watch): space out overflow sweeps and cap background scans at two - #89
Merged
Merged
Conversation
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>
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.
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
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.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
WatchFullRescanSpacingsuite: 4 tests, all ran (checked in the result XML). Full suite: 295 tests, 0 failures.