Repository navigation
Check HEAD before walking every ref when creating a worktree - #7066
Merged
ymichael merged 1 commit intoNov 5, 2026
Merged
Conversation
readGitRepositoryState ran `git rev-list --all --max-count=1` on every worktree create. That sorts the tip commit of every ref, which costs 0.8-2.7 s on a checkout with ~4.5k branches. Verify HEAD first and only walk all refs when HEAD is unborn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/rev-list-all-on-every-worktree-create-thr_s36unefz3u
branch
November 5, 2026 00:48
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.
Human comments
What was wrong
Every worktree create checks that the source repository has a commit (
readGitRepositoryStateinpackages/environment-provider-host/src/git.ts). It did this withgit rev-list --all --max-count=1. Even with--max-count=1, git has to load and date-sort the tip commit of every ref before it can print one. On a checkout with thousands of branches, that is the slowest git call in thread creation, and the caller only needs to know whether any commit exists. This is finding #7 of the Nov 4 hot-path audit.What changed
readGitRepositoryStatenow runsgit rev-parse --verify --quiet HEAD^{commit}first. If HEAD resolves to a commit, it returnshas_commitsstraight away.rev-list --allonly when HEAD is unborn. That keeps the existing result for an orphan HEAD when other branches have commits.not_git,no_commits,has_commits) still maps to the same result and the same error.HOST_DAEMON_PROTOCOL_VERSIONbump. No plugin SDK change.How you verified
Real data:
~/Projects/bb(4,477 local branches, 2,671 remote refs, 123 worktrees, git 2.50.1). I called the realreadGitRepositoryStatefrom this branch and compared it with main's function body, run through the samedetectGitSource/runGitrunner. Runs were interleaved, after one warm-up each.Both columns include the shared
rev-parse --is-inside-work-treedetection spawn. In both runs the branch took one fast spawn where main took a ref walk whose cost grows with load.Tests:
packages/environment-provider-host/test/git.test.ts. It covers a plain directory, an empty repository, a commit on HEAD, an unborn HEAD with commits on another branch (the fallback path), and a bare clone.pnpm exec turbo run typecheck lint --filter=bb-environment-provider-hostpasses.🤖 Generated with Claude Code