perf: Optimize engine builder, task visitor, and untracked file discovery#11956
Merged
anthonyshew merged 2 commits intomainfrom Feb 21, 2026
Merged
perf: Optimize engine builder, task visitor, and untracked file discovery#11956anthonyshew merged 2 commits intomainfrom
anthonyshew merged 2 commits intomainfrom
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…very Three targeted optimizations to the turbo run hot path: 1. Engine builder: Cache turbo.json chain per package and move the visited check before the expensive task_definition() call. The chain only depends on the package name, so multiple tasks in the same package reuse the cached result. 2. Task visitor: Defer env() computation to non-dry-run branches. The execution environment is unused during dry runs, avoiding per-task RwLock acquisition and env var map cloning. 3. find_untracked_files: Replace Mutex<Vec> with per-thread local buffers flushed via mpsc channel on drop, eliminating per-file mutex contention in the parallel walker.
c862371 to
d996522
Compare
Contributor
Coverage Report
|
github-actions Bot
added a commit
that referenced
this pull request
Feb 21, 2026
## Release v2.8.11-canary.19 Versioned docs: https://v2-8-11-canary-19.turborepo.dev ### Changes - release(turborepo): 2.8.11-canary.18 (#11954) (`ef22b25`) - perf: Resolve literal input paths via stat instead of glob walk (#11955) (`b0048b0`) - perf: Optimize engine builder, task visitor, and untracked file discovery (#11956) (`e145bc6`) --------- Co-authored-by: Turbobot <turbobot@vercel.com>
github-actions Bot
added a commit
that referenced
this pull request
Feb 22, 2026
## Release v2.8.11-canary.20 Versioned docs: https://v2-8-11-canary-20.turborepo.dev ### Changes - perf: Optimize engine builder, task visitor, and untracked file discovery (#11956) (`e145bc6`) - release(turborepo): 2.8.11-canary.19 (#11957) (`be8c782`) - perf: Parallelize `turbo run` pre-execution hot path (#11958) (`b79b680`) --------- Co-authored-by: Turbobot <turbobot@vercel.com>
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
Three targeted optimizations to the
turbo runhot path, focused on areas identified via--profileon repos of varying sizes.Benchmarks
Hyperfine (30 runs, 10 warmup) comparing mainline to this branch across three internal monorepos:
Large repo (~1000 packages)
build_engineself-time: 283ms → 74ms (−74%).queue_taskself-time: 330ms → 181ms (−45%).Medium repo (~120 packages)
Small repo (~5 packages)
The optimizations scale with
packages × tasks, so the large repo sees the most benefit. Medium and small repos are dominated by filesystem I/O (find_untracked_files) and lockfile parsing, which are unaffected.Changes
visitedset check beforetask_definition(). The chain resolution only depends on the package, not the task, so all tasks in the same package share the cached chain. The earlyvisitedcheck avoids recomputing task definitions for duplicate BFS entries.env()call to the non-dry-run branch. The execution environment map is unused during dry runs, so this skips per-task RwLock acquisition,DetailedMapcloning, and wildcard regex matching in that path.find_untracked_files: ReplaceMutex<Vec>with per-thread local buffers that flush viampscchannel on drop. This eliminates per-file mutex contention in the parallel directory walker.Testing
All existing tests pass across the three modified crates:
turborepo-engine: 62 tests (covers extends chains, cycles, diamond inheritance,extends: false, BFS graph construction)turborepo-scm: 110 tests (covers untracked file detection, git index equivalence, package boundary isolation)