Repository navigation
Reduce CPU from source-control git polling on Windows - #6736
Conversation
On Windows, source-control polling's upstream-probe round spawned up to ~8 short-lived 'git config --get' processes (each scanned by Windows Defender), driving periodic CPU. Coalesce all per-round config reads into a single 'git config --list -z' snapshot behind the existing runGit abstraction, wired into both the local and SSH relay probe paths. No change to poll cadence, cache TTLs, staleness, or the resolved upstream/push-target result — only the per-round subprocess count drops (~10 to ~4 git processes for a no-upstream branch). Fixes #6381 Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughA shared utility, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 21feb758-2b8d-4295-a537-c5467de6ee5a
📒 Files selected for processing (7)
src/main/git/status-upstream-negative-cache.test.tssrc/main/git/status-upstream-probe-churn.test.tssrc/main/git/status.tssrc/relay/git-status-upstream-negative-cache.test.tssrc/relay/git-status-upstream-negative-cache.tssrc/shared/git-config-snapshot-runner.test.tssrc/shared/git-config-snapshot-runner.ts
A snapshot miss previously resolved to empty success; real `git config --get` exits non-zero for an absent key. Throw a typed not-found error instead so the wrapper stays a faithful drop-in for any caller. The sole probe-path consumer catches and maps to null, so resolution is unchanged, and misses are still served from the loaded snapshot (no real-git passthrough that would re-spawn the coalesced subprocess). Adds a regression for the loaded-snapshot missing-key path (CodeRabbit). Co-authored-by: Orca <[email protected]>
|
@coderabbitai review |
✅ Action performedReview finished.
|
Co-authored-by: Orca <[email protected]>
What changes
Source-control polling's background upstream check used to spawn a burst of short-lived
gitprocesses each time it ran for a branch with no upstream — up to ~8 separategit config --getcalls per probe round (plus therev-parse/symbolic-refreads). On Windows, every spawn is scanned by Windows Defender, so the churn surfaced as periodic CPU. This collapses all of a probe round'sgit config --getreads into onegit config --list -zsnapshot, dropping a no-upstream probe round from ~10 to ~4gitprocesses.What does NOT change
No change to how often the probe runs (the 3 s poll cadence and the 5-minute no-upstream negative cache are untouched), no change to caching/staleness, and no change to the resolved upstream or push-target — only the number of
gitsubprocesses spawned per round.git remote/git remote get-urlare intentionally left as real-git calls (they are not on the steady-state polling path).Closes #6381.
Background
This is the residual tail of the source-control git-burst work. Prior releases (v1.4.94–v1.4.101 and the upstream/push-target fix that followed) already eliminated the recurring bursts; the reporter confirmed on v1.4.103 that peak concurrent git dropped from ~10 to 3 with no sustained bursts, leaving only a low-rate
config/rev-parse @{u}probe set. This change targets that remaining per-round fan-out so each residual refresh spawns materially fewer processes — which is what the on-access AV scanning cost scales with.Design approach
A small
runGitwrapper,createGitConfigSnapshotRunner, intercepts onlygit config --get <key>calls. On the first such call in a round it lazily fetchesgit config --list -zonce (single-flighting the in-flight promise so the resolvers' concurrentPromise.allreads share one fetch), parses it into a key → ordered-values map, and serves every subsequentconfig --getfrom that snapshot. Lookups apply git's key canonicalization (lowercase the section and final key segment, preserve the subsection) and multivar--getlast-wins semantics, so a served value is byte-identical to what realgit config --getwould return. If the snapshot fetch fails for any reason, interception is disabled for the round and calls fall back to real git, preserving today's behavior exactly. The wrapper is created fresh per probe round, so there is no cross-round config caching (staleness is unchanged).Wired into the two polling probe sites that drive the residual churn:
probeEffectiveUpstreamStatus(local,src/main/git/status.ts) andreadOrProbeNoEffectiveUpstreamStatus(SSH relay,src/relay/git-status-upstream-negative-cache.ts). The same-name-originrev-parsedetection stays on the outer runner in both, so the negative-cache write gate is unaffected.Design-review outcome
Ran an iterative design review on the doc. It caught a real correctness bug in an earlier draft (a multivar value would have been resolved first-wins when
git config --getis actually last-wins) and a single-flight gap (memoizing the parsed value instead of the in-flight promise would have let concurrent first-calls each spawnconfig --list); both were fixed before implementation. The review also flagged that synthesizinggit remoteoutput in the wrapper re-implemented too much git behavior with silent wrong-resolution risk — so the final scope was narrowed to intercept onlyconfig --getand leaveremote/remote get-urlas real-git pass-through, which keeps the full per-round saving for the common case while removing the riskiest surface.Implementation & deviations
Implemented as designed. One in-scope addition beyond the listed files:
src/main/git/status-upstream-negative-cache.test.tsmocks needed to handle the newconfig --list -zsubprocess shape, so it was updated alongside the churn tests. No other deviations.Completeness verification
A read-only verification pass mapped every design requirement, edge case, and validation item to a PASS with file:line evidence, and empirically confirmed against real git that the served values match for the queried key shapes (including the
feature/fixslash subsection). Verdict: complete, no behavior change beyond subprocess-count reduction.Headline behavior status
Implemented in production code on the real polling path (both local and relay probe sites execute the coalescing — not behind a flag or fixture). The deterministic churn tests assert the spawn-count reduction on the production path.
Perf audit
Touched hot paths: the 3 s source-control poll's upstream probe and its SSH-relay equivalent. The audit confirmed the change strictly reduces spawn count with no new per-poll cost (the wrapper only instantiates inside a probe round, which is itself gated by the negative cache), no leak (per-round closure, fallback
.catchobserved so no unhandled rejection), and correct composition with the existing in-flight dedup / negative cache. A large-config timing check (~88 KB, 2300+ entries) showedgit config --list -zruns in ~0.05 s — process spawn dominates, so one--listis cheaper than the several--gets it replaces even on big configs. No measurement gap: the deterministic "exactly oneconfig --list, zeroconfig --getper round" tests are the correct proxy for the churn-reduction claim.Code-review loop
Two independent reviewers in one round (one Codex, one Claude), both adversarially targeting any case where a snapshot-served value could diverge from real
git config --get. Both returned clean — no P0/P1/P2 actionable findings. Each independently validated the parser, key canonicalization, single-flight, fallback, and the.trim()consumer equivalence against the real git binary.Validation
pnpm run typecheck— pass.pnpm exec oxlint(repo-wide) — 0 errors (one pre-existing unrelated warning inuseGitStatusPolling.ts, not modified here).git-config-snapshot-runner.test.ts,status-upstream-probe-churn.test.ts,status-upstream-negative-cache.test.ts, relaygit-status-upstream-negative-cache.test.ts— 29 pass.src/main/git/+git-effective-upstream+git-configured-branch-target) — 384 pass.git config --getacross mixed-case / slash-subsection / dotted-name / multivar / missing keys;getEffectiveGitUpstreamStatusresolves identically with vs without the wrapper while spawning 1config --list+ 0config --get.Cross-platform & SSH
Pure shift in git argument shape behind
runGit— no OS-specific code, no path assumptions, no shell. The reduction is real on macOS/Linux too; it's largest on Windows where each spawn carries the Defender-scan cost. The SSH relay probe path is wired with the same wrapper, so remote worktrees get the same one-for-one reduction.Accepted gaps
The actual Windows-Defender CPU drop can't be observed from a macOS dev box; this issue is Windows-specific. The root cause the reporter identified is spawn cadence ("the same churn would tax any on-access AV"), and that reduction is proven deterministically and against real git.
Made with Orca 🐋
Post-PR stabilization
verifyandtrack-community-prpass.GitConfigSnapshotKeyNotFoundErrorto matchgit config --get's exit-1 contract (without re-spawning real-git, which would defeat the coalescing); (2) Minor — added a loaded-snapshot missing-key regression test. No remaining actionable comments.