perf(config): cache isGitIgnored result per process lifetime (#1898)
loadConfig() calls isGitIgnored() which spawns a git check-ignore subprocess. The result is stable for the process lifetime but was being recomputed on every call. With 28+ loadConfig call sites, this could spawn multiple redundant git subprocesses per CLI invocation. A module-level Map cache keyed on (cwd, targetPath) ensures the subprocess fires at most once per unique pair per process. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -400,7 +400,11 @@ function loadConfig(cwd) {
|
||||
|
||||
// ─── Git utilities ────────────────────────────────────────────────────────────
|
||||
|
||||
const _gitIgnoredCache = new Map();
|
||||
|
||||
function isGitIgnored(cwd, targetPath) {
|
||||
const key = cwd + '::' + targetPath;
|
||||
if (_gitIgnoredCache.has(key)) return _gitIgnoredCache.get(key);
|
||||
try {
|
||||
// --no-index checks .gitignore rules regardless of whether the file is tracked.
|
||||
// Without it, git check-ignore returns "not ignored" for tracked files even when
|
||||
@@ -412,8 +416,10 @@ function isGitIgnored(cwd, targetPath) {
|
||||
cwd,
|
||||
stdio: 'pipe',
|
||||
});
|
||||
_gitIgnoredCache.set(key, true);
|
||||
return true;
|
||||
} catch {
|
||||
_gitIgnoredCache.set(key, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user