Repository navigation
perf: gc reports ask git each question once - #6627
Merged
Merged
Conversation
janicduplessis
force-pushed
the
perf/6615-gc-git-calls
branch
from
November 28, 2026 06:43
e14c7e2 to
d8cae4d
Compare
janicduplessis
force-pushed
the
perf/6615-gc-git-calls
branch
from
November 28, 2026 06:46
d8cae4d to
958fd16
Compare
janicduplessis
marked this pull request as ready for review
November 28, 2026 06:48
janicduplessis
enabled auto-merge (squash)
November 28, 2026 06:49
This was referenced Nov 29, 2026
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.
Description
On the maintainer's MacBook (258 registered projects),
stim gc --dry-run --jsonruns about 6,600 git commands, and about 4,200 of them have the same folder and arguments as an earlier one (#6615). The cause is one call: the dependency pass lists worktrees throughartifactWorktreesFor, which always drops the run's shared git reads (forgetGitReads), even in a report where nothing acts. That drop sits between the plan's worktree sweep and the report's second sweep (collectGcReport), so the second sweep reads every checkout again. Merge state (patch-id,log -p,diff) also never went through the shared reads, and concurrent sweeps of one repository each ran their owngit worktree list.Maintainer decision: "can scan like stream in, and is it possible to further reduce git calls", 2026-11-27 (#6615 comment). The streaming half is #6613 and is not in this PR.
Solution
Everything stays in the git-read layer and its call sites. The report, cache and streaming code that #6612 and #6613 change is not touched.
checkMergeStateskeys each worktree's merge state on its HEAD, its branch and the commit the default branch points to. That commit is read fresh with onerev-parseper repository per sweep, so a fetch or a movedorigin/maingets a new answer. Theorigin/HEADlookup, the removal holds (registeredRemovalHold,discoveredRemovalHold) anduncommittedActivityOfare shared per sweep through the existingsweep\0...keys. The fresh rechecks under the removal locks (removalUseHold, the normal-observation recheck) are unchanged.git worktree listper repository. In an open scope,listWorktreesAsynckeys the listing on the on-disk common directory, so concurrent sweeps of the stim repository's 38 worktrees ask git once instead of 38 times. The on-disk probe goes throughbounded-read.ts(3 s, abortable); an unanswered probe, an empty listing, or a listing that does not contain the checkout falls back to that checkout's owngit worktree list.check-ignoreonce per depth instead of once per folder.scanSourceWritesreads one depth at a time and sends all of that depth's build-named folders in onegit check-ignore -z --stdin. git refuses the whole list when one path is inside a submodule (fatal: Pathspec ... is in submodule), so on any failure other than exit 1 the walk asks again folder by folder when more than one folder at that depth had candidates. A refusal costs one extra call per depth over the per-folder walk. A walk now reads a whole depth before it checks entry times, so on an active checkout it can read a few more folders before it stops at the first recent write.LLP 0001 gains "A report asks git each question once" and LLP 0004's source-scan section describes the per-depth probe.
One case is left out on purpose: a bare repository nested inside another checkout would be keyed on the outer repository's common directory. Normal layouts don't do that, and the worst case is a wrong listing for that run's report.
Not done here: a merge-state cache across runs (stimd reruns the report every 15 minutes, and the CLI is one-shot). The removal reads that make up the remaining per-worktree cost (
status --porcelain=v2,log --oneline HEAD --not,rev-parse --git-path modules,ls-files --stage) depend on working-tree files as well as refs, so keying them on HEAD or index mtimes would not be safe.Test plan
Measured on the maintainer's MacBook (load average 8 to 10) by logging every git child through a PATH shim. The shim hashes stdin so
check-ignoreandpatch-idcalls with different input count as different calls:stim gc --dry-run --jsongc({measureBuildState: false})(Desktop's path in stimd)check-ignorecalls (CLI)worktree listcalls (CLI)git check-ignore -z --stdinwas checked against the real git (2.54): it echoes nested relative paths as given, exits 1 when nothing is ignored, and exits fatally for a path inside a submodule (invariant 9).git-reads.integration.test.tscover these cases:origin/mainmoves;check-ignoreonce per depth, then per folder when a submodule fails the batch, and still skips the ignoredbuild/;Fixes #6615