refactor(core): combine git discovery queries#36321
Merged
Merged
Conversation
This was referenced Jul 11, 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.
Summary
git rev-parsesubprocessContext
After #36290 removed eager Snapshot discovery from Location acquisition, Git discovery remained a smaller measured first-use cost.
Git.repo.discover()previously launched three sequential subprocesses after locating.git:This PR asks Git for the same metadata in one process:
The required Git and common directories are emitted first. If
--show-toplevelfails because the repository has no work tree, discovery retains the previous behavior by using the discovered.gitparent asworktree. Discovery still returnsundefinedwhen the required directory fields are unavailable.Benchmark
An alternating 20-run benchmark executed discovery metadata queries concurrently across five repositories. It used three warmups and compared the previous three-process sequence with the combined command in alternating order.
The combined query reduced the measured batch median by 65%. An earlier run before rebasing measured
23.3 ms → 12.2 ms(-48%), so the direction is durable across both runs.This deliberately does not change the preceding filesystem ascent or add cross-call discovery caching. Those are separate behaviors and were not needed to test the subprocess-count hypothesis.
Compatibility
.gitmetadata is present but whose work tree is disabled retain the previouscwdworktree fallbackundefinedVerification
bun typecheckfrompackages/core: passedbun run test test/git.test.ts test/snapshot.test.tsfrompackages/core: 10 passedFollow-up to #36285 and #36290.