Skip to content

pr-git-2501/stepancheg/fsmonitor-skip-prep-exclude-v1

tagged this 22 Nov 22:29
From: Stepan Koltsov <stepan.koltsov@gmail.com>

"git status" calls prep_exclude() for every directory in the
untracked cache, to drop a cache entry if its .gitignore rules
changed. That matches every directory against the exclude patterns
and reads every .gitignore. With fsmonitor it is unnecessary:
fsmonitor already drops the cache entry when anything in the
directory changes, including .gitignore.

Skip the call in valid_cached_dir() when fsmonitor is on and the
cache entry is still valid.

One case is left: a .gitignore is edited while the monitor is not
watching, for example while the daemon is stopped. The monitor then
sends a trivial response. Since 1cf98cb4d9 (fsmonitor: check the
untracked cache after a trivial response, 2026-11-09) the cached
directories are rechecked after one, but only by their stat data.
Editing a file in place does not change the stat data of its
directory, so only prep_exclude() notices the edit. Make that
recheck also invalidate every directory that has a .gitignore.

This is a trade-off: each such directory is read again once per
trivial response. Hashing its .gitignore instead would avoid that,
but would have to reproduce how add_patterns() chooses the object
name it records, so prefer the simpler check.

On macOS with the builtin fsmonitor daemon, in a tree of about
89,000 directories with a warm untracked cache,
"git status --untracked-files=all" went from about 310 ms to about
65 ms, and the time spent in read_directory() from about 255 ms to
about 8 ms.

Assisted-by: LLM
Signed-off-by: Stepan Koltsov <stepan.koltsov@gmail.com>

Submitted-As: https://lore.kernel.org/git/pull.2501.git.git.1795386591089.gitgitgadget@gmail.com
Assets 2
Loading