You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: Reduce git subprocess calls on startup (#11934)
## Summary
Reduces the number of sequential git subprocess calls on the critical
startup path from 5 to 1.
| Repo size | Before | After | Speedup |
|---|---|---|---|
| Small (1 package) | 868ms ± 27ms | 757ms ± 25ms | **1.14x** |
| Medium (~10 packages) | 1.233s ± 0.063s | 1.127s ± 0.038s | **1.09x**
|
| Large (~50 packages) | 1.896s ± 0.124s | 1.735s ± 0.086s | **1.09x** |
Measured with `hyperfine --warmup 5` on `turbo run <task> --skip-infer
--dry`. "Before" is main with the shared HTTP client optimization
already applied.
## What changed
### 1. Combined worktree detection into a single git call
`WorktreeInfo::detect` previously spawned two separate `git rev-parse`
subprocesses (`--show-toplevel` and `--git-common-dir`). Now it runs a
single `git rev-parse --show-toplevel --git-common-dir --show-cdup` and
parses all three results from the output. The `--show-cdup` result (git
root) is stored on `WorktreeInfo` so it can be reused later by
`SCM::new`.
### 2. Deferred run summary git calls to finish time
`RunTracker::new` previously called `SCMState::get()` eagerly, which
spawns `git branch --show-current` and `git rev-parse HEAD` — two
subprocesses purely for run summary metadata. These have no impact on
task execution or caching. They're now computed in `to_summary()`, after
tasks complete.
### 3. Reuse git root from worktree detection in SCM::new
`SCM::new` previously spawned its own `git rev-parse --show-cdup` to
find the git root — the same information already resolved during
worktree detection. Now the git root flows from `WorktreeInfo` →
`CacheDirResult` → `Opts` → `RunBuilder`, and `SCM::new_with_git_root`
skips the redundant subprocess entirely.
Together this reduces 5 sequential subprocess spawns on the critical
path to 1 (the combined worktree detection call), with the 2 summary
calls deferred to after task execution.
## Testing
- All 5 worktree tests pass with new `git_root` assertions (main
worktree, linked worktree, subdirectories, non-git directories)
- The deferred SCMState has no early readers — the `scm` field was
removed from `RunTracker` entirely
0 commit comments