Repository navigation
Stop watching folders git ignores - #98
Merged
Merged
Conversation
A repo's watch is one recursive registration on its folder, so a build's output is walked at registration and every write a build makes there arrives as an event. One field report traced 97% of a repo's events, and half of all the app's rescans, to its build/ folder. Those events are dropped before they reach the debounce, but the folder is still walked and watched. Each repo is now watched as a shallow watch on its folder, plus a recursive watch on each top-level folder that git doesn't ignore or that has tracked files in it. .git is always watched. A repo that ignores nothing keeps the single recursive watch. git is asked before anything is registered, so an ignored folder is never walked. This was tried before and withdrawn because every registration created its own inotify instance: 36 repos took 258 of the machine-wide 512. Nucleus 3.0.0 shares one native watcher across all of a watcher's registrations (NucleusFramework/Nucleus#571). A test now pins that against the real watcher by counting inotify instances in /proc. The watched set follows the repo's layout. The shallow watch reports a top-level folder appearing, going or being renamed, and a change to .gitignore or .git/info/exclude. git is asked again, and only the registrations that differ are added or closed. 3.0.0 events say whether a path is a directory, so saving a top-level file does not ask git anything. The event filter for ignored folders is removed: nothing inside them is watched any more, so it could never apply. Signed-off-by: Raman Gupta <rocketraman@gmail.com>
rocketraman
force-pushed
the
prune-ignored-watches
branch
from
December 2, 2026 16:42
41f2794 to
22944b7
Compare
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.
Stops watching the folders git ignores, such as
build/andnode_modules/. Each repo is currently one recursive watch on its folder, so a build's output is walked when the watch is registered, and every write a build makes there arrives as an event. One field report traced 97% of a repo's events to itsbuild/. Those events are already dropped before they trigger a rescan, but the folder is still walked and watched.Stacked on the Nucleus 3.0.0 update, which this depends on.
What changes
Watch set (
WatchRoots.kt,AppState.kt). A repo with ignored folders is watched as:.idea/with a shared run configuration is still watched);.gitalways, because it's how commits, checkouts and fetches are noticed.A repo that ignores nothing keeps the single recursive watch. Symlinked folders are skipped, as the recursive watch never followed them. git is asked before anything is registered, so an ignored folder is never walked, not even at startup.
Why this is safe now. This was tried before and withdrawn. Each registration created its own inotify instance, from a limit shared with every process on the machine, and 36 repos used 258 of 512. Nucleus 3.0.0 shares one native watcher across all of a watcher's registrations (NucleusFramework/Nucleus#571), and the app uses one watcher.
WatchInstanceCostpins this against the real watcher on Linux: it counts inotify instances in/proc/self/fdand fails if 12 registrations take more than one.Following layout changes (
WatchPolicy.ignoresStale,AppState.refreshIgnoredDirs). git is asked again after:.gitignoreor.git/info/exclude.Only the registrations that differ are added or closed, and new ones are added before old ones close. The watcher's
isDirectoryflag is now passed toignoresStale(AppState.eventIsDirectory), so saving a top-level file doesn't ask git anything.Removed. The event filter for ignored folders (
WatchPolicy.inIgnoredDirs, and theroot/ignoredparameters ofactionFor). Nothing inside those folders is watched any more, so the filter could never apply.Verification
./gradlew check: 306 tests, 0 failures. The new inotify test was checked to be able to fail: with a temporary probe, 12 registrations on one watcher cost 1 instance, and 12 separate watchers cost 12. It reads/proc, so it only asserts on Linux; on macOS and Windows it returns without checking anything.Live run in an isolated KWin session against a scratch repo with
build/ignored, reading the process's inotify watches from/proc:build/andbuild/classesmkdir appapp/gained a watch within 3s; a file in it showed as "1 untracked" on the dashboard at oncebuild/app/src/App.ktReviewer notes
WatchRoots.ignoredDirsis twogitruns per repo, run in turn underwatchMutexat startup. Before, the same query ran after registering. Timed across 45 real tracked repos (warm cache): 116ms in total, 7ms at most for one repo, off the UI thread. 39 of the 45 have ignored folders that are now skipped instead of walked.node_modulesper monorepo package, is still walked; finding those would mean the walk this avoids.