Skip to content

perf(test): faster local test loop and cold-worktree changed runs - #33421

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fast-test-loop
Oct 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fast-test-loop

Conversation

@nwparker

@nwparker nwparker commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​127 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​124
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​503 $\color{#cf222e}{\Huge{\mathbf{−}}}$​64 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​439

What changed

  • test:changed with no changes exits before Vitest starts. It uses git status (plus diff <ref>...HEAD for a ref) as the check. Unlike ls-files --modified, git status refreshes stale index stat data instead of rehashing files. The scripts also stop nesting pnpm run calls.
  • Fresh worktrees: recordDependencies records are per checkout, so a new worktree's first test:changed ran every test. A small Vitest patch keeps per-test records. When more than 100 tests in scope have no record, those tests are selected with Vitest's static import graph instead of all running. When 100 or fewer lack a record, they still run, which records them. A missing record therefore still means the test runs or is covered by the static graph. CI does not record, so it is unaffected.
  • Bun config load (0.9–2.9s): the cause was the SQLite import scan statting all ~13.6k unit tests during config evaluation, not Bun itself. On a filtered run, only the tests the filters can select get classified. This mirrors Vitest's substring and file:line matching and never selects fewer files than Vitest does. Watch, related, --dir and --root still scan everything. The scan also walks directories instead of using fs.globSync. The native config loader notice is silenced.
  • Zod test bundle is content-addressed and reused (it was rebuilt each run, 130–220ms). Because nothing is created per run, a killed run leaks nothing. vitest-zod-* directories that older launchers leaked are swept once they are more than 6h old.
  • build:packages skips compiling when process-host sources, the build script, the exact TypeScript/tsx/@types/node installs, and the dist file sizes and mtimes are unchanged.

Timings

Heavily loaded macOS machine (load average 30–100). Base and branch were interleaved, 6 runs each, in sibling worktrees. Times are wall-clock medians, with the minimum in parentheses.

Scenario Before After
pnpm test src/shared/app-version.test.ts --maxWorkers=2 4.44s (3.02) 2.12s (1.22)
pnpm test src/shared/worktree --maxWorkers=2 (24 files) 8.69s (5.58) 6.35s (3.97)
pnpm test:changed, no changes 7.66s (3.04) 1.30s (0.50)
build:packages, unchanged ~0.35s compile + pnpm/tsx startup 0.06–0.10s
Fresh worktree, --changed touching a widely imported shared type runs all 13,609 files static selection of 1,854 files in 218s (under load)

The last row is selection only (vitest list --filesOnly); the selected files then run.

Runner choice

Bun hosting stays. It was adopted for multi-file throughput, and CI runs suites on Bun, so local single-file runs keep the same runtime. After this change, a single file still takes about 0.9s through the Bun launcher versus about 0.5s with plain Node Vitest. For about 20 files the two are within noise.

Tests

Added tests: run-filter parsing (inherited arguments ignored, never narrower than Vitest), the changed precheck, and Zod bundle reuse/sweep. The SQLite cache test was updated for the walker. Targeted suites, pnpm tc and check:code-quality:changed pass.

- test:changed exits before starting Vitest when Git reports no changed files.
- Unrecorded tests beyond 100 in scope use Vitest's static import graph instead
  of all running, so a fresh worktree's first changed run no longer runs the
  whole suite (patched RecordedModulesResolver; CI does not record, unchanged).
- Bun's slow config load was the SQLite import scan statting every unit test;
  filtered runs now classify only the tests their filters can select, and the
  scan walks directories instead of fs.globSync.
- Silence the native config loader notice on every run.
- Zod's test bundle is content-addressed and reused, so a killed run leaks
  nothing; leaked per-run directories older than 6h are swept.
- build:packages skips compiling when package inputs, compiler, and dist are
  unchanged; test scripts no longer nest pnpm invocations.
@nwparker
nwparker marked this pull request as ready for review October 25, 2026 05:53
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 434bedd3-7e67-4e2f-9190-8693e3fb21e3
Commits

Reviewing files that changed from the base of the PR and between 8e9f86b and 1356905.

Files ignored due to path filters: 1
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 16
  • .github/CONTRIBUTING.md
  • config/patches/[email protected]
  • config/scripts/build-workspace-packages.mjs
  • config/scripts/run-vitest.mjs
  • config/scripts/vitest-changed-precheck.mjs
  • config/scripts/vitest-changed-precheck.test.mjs
  • config/scripts/vitest-node-runtime-files.mjs
  • config/scripts/vitest-run-filters.mjs
  • config/scripts/vitest-run-filters.test.mjs
  • config/scripts/vitest-sqlite-runtime-cache.test.ts
  • config/scripts/vitest-sqlite-runtime-scan.mjs
  • config/scripts/vitest-zod-bundle.mjs
  • config/scripts/vitest-zod-bundle.test.mjs
  • config/vitest.config.ts
  • package.json
  • pnpm-workspace.yaml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit e4bbbe0 into main Oct 25, 2026
101 checks passed
@nwparker
nwparker deleted the nwparker/fast-test-loop branch October 25, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant