Skip to content

Reduce CPU from source-control git polling on Windows - #6736

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/issue-6381-source-control-git-bursts
Jun 29, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/issue-6381-source-control-git-bursts

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

What changes

Source-control polling's background upstream check used to spawn a burst of short-lived git processes each time it ran for a branch with no upstream — up to ~8 separate git config --get calls per probe round (plus the rev-parse/symbolic-ref reads). On Windows, every spawn is scanned by Windows Defender, so the churn surfaced as periodic CPU. This collapses all of a probe round's git config --get reads into one git config --list -z snapshot, dropping a no-upstream probe round from ~10 to ~4 git processes.

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 git subprocesses spawned per round. git remote / git remote get-url are 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 runGit wrapper, createGitConfigSnapshotRunner, intercepts only git config --get <key> calls. On the first such call in a round it lazily fetches git config --list -z once (single-flighting the in-flight promise so the resolvers' concurrent Promise.all reads share one fetch), parses it into a key → ordered-values map, and serves every subsequent config --get from that snapshot. Lookups apply git's key canonicalization (lowercase the section and final key segment, preserve the subsection) and multivar --get last-wins semantics, so a served value is byte-identical to what real git config --get would 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) and readOrProbeNoEffectiveUpstreamStatus (SSH relay, src/relay/git-status-upstream-negative-cache.ts). The same-name-origin rev-parse detection 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 --get is 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 spawn config --list); both were fixed before implementation. The review also flagged that synthesizing git remote output in the wrapper re-implemented too much git behavior with silent wrong-resolution risk — so the final scope was narrowed to intercept only config --get and leave remote/remote get-url as 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.ts mocks needed to handle the new config --list -z subprocess 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/fix slash 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 .catch observed so no unhandled rejection), and correct composition with the existing in-flight dedup / negative cache. A large-config timing check (~88 KB, 2300+ entries) showed git config --list -z runs in ~0.05 s — process spawn dominates, so one --list is cheaper than the several --gets it replaces even on big configs. No measurement gap: the deterministic "exactly one config --list, zero config --get per 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 in useGitStatusPolling.ts, not modified here).
  • Focused: git-config-snapshot-runner.test.ts, status-upstream-probe-churn.test.ts, status-upstream-negative-cache.test.ts, relay git-status-upstream-negative-cache.test.ts — 29 pass.
  • Broader git suites (src/main/git/ + git-effective-upstream + git-configured-branch-target) — 384 pass.
  • Real-git integration check (scratch, not shipped): snapshot runner byte-identical to real git config --get across mixed-case / slash-subsection / dotted-name / multivar / missing keys; getEffectiveGitUpstreamStatus resolves identically with vs without the wrapper while spawning 1 config --list + 0 config --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

  • CI: verify and track-community-pr pass.
  • CodeRabbit raised two findings on the config-snapshot runner, both addressed in 56dedc9 and acknowledged by CodeRabbit: (1) Major — an absent key now throws a typed GitConfigSnapshotKeyNotFoundError to match git 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.

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]>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A shared utility, createGitConfigSnapshotRunner, is added to intercept git config --get calls by loading and parsing a single git config --list -z snapshot. It is wired into upstream probing in src/main/git/status.ts and src/relay/git-status-upstream-negative-cache.ts. Related tests now mock the snapshot command and include coverage for coalesced config reads, snapshot parsing, and fallback behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: reducing Windows CPU by cutting source-control git polling churn.
Linked Issues check ✅ Passed The PR coalesces repeated git config reads into one snapshot in both polling paths, reducing process churn without changing upstream behavior.
Out of Scope Changes check ✅ Passed The changes stay focused on git config snapshotting, related status wiring, and supporting tests; no unrelated edits are apparent.
Description check ✅ Passed The description is detailed and covers the change, testing, review, cross-platform notes, and caveats, even though it doesn't follow the template headings exactly.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 21feb758-2b8d-4295-a537-c5467de6ee5a

📥 Commits

Reviewing files that changed from the base of the PR and between d877d94 and 2cdf892.

📒 Files selected for processing (7)
  • src/main/git/status-upstream-negative-cache.test.ts
  • src/main/git/status-upstream-probe-churn.test.ts
  • src/main/git/status.ts
  • src/relay/git-status-upstream-negative-cache.test.ts
  • src/relay/git-status-upstream-negative-cache.ts
  • src/shared/git-config-snapshot-runner.test.ts
  • src/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]>
@brennanb2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@brennanb2025
brennanb2025 merged commit 90d3d7a into main Jun 29, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/issue-6381-source-control-git-bursts branch June 29, 2026 22:25
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Source-control polling spawns recurring git.exe bursts → periodic CPU — Windows, v1.4.97

1 participant