Repository navigation
Conversation
A 1500-module shared tree, 800 test files, and 6 setup files that each vi.mock a service. A reused worker re-runs the setup files before every file, so per-file and per-run-request costs show up here and nowhere else. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.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.
vitest-dev/vitest#11752 reports a 6,600-file suite with
isolate: falseand setup files thatvi.mockmodules going from 96 s to 58 s with its changes. In that shape a reused worker runs those setup files again before every test file, so anything Vitest does per file or per run request, such as resolving the setup files and their mock paths or asking the main process for warm modules, repeats hundreds of times per worker, and each round trip waits behind the other workers' calls on the main thread. No existing app has mocking setup files, so none of them can see this cost. This addssetup-mocks, a shared tree of 1500 modules that every test file evaluates, 800 test files that each also import one module of their own, and 6 setup files that each mock a service the tests assert on.The default matrix runs only
isolate: false, becauseisolate: truere-evaluates the whole tree for every file and takes about a minute per rep. The 25% and 50%maxWorkersrows are there to show how per-file round trips scale with the number of workers. The app passes on the pinned 4.1.10, and the README section leaves its 4.1.10 vs 5.0.0 table for a later measurement.Benchmark: vitest main vs vitest-dev/vitest#11752
Setup:
maxWorkersdefaults to 11; 25% is 3 and 50% is 6.5.1.0-beta.1: main at1a77c6cbc(the PR's parent) and the PR head6fbc6ae58. Each is linked by pointing the app'snode_modules/vitestat itspackages/vitest.vitest run.setup-mocks
The default matrix,
pnpm bench --apps setup-mocks --runs 5, in two rounds: main, PR, main, PR. ThemaxWorkers: 1row was added to the matrix afterwards and measured on its own with the same protocol. Main and PR are the median of all 10 runs; the last column is the change within each round.The PR is faster in every cell in both rounds: by 16–40% on the pooled medians and 13–42% within single rounds, and the two rounds agree within 8 points. The largest gains are with warm
fsModuleCache(−40% forks, −38% threads) and with forks at 25%maxWorkers(−36%).With
maxWorkers: 1, all files go to the one worker as a single run request, so the PR's kept snapshot changes nothing there (main fetches it once too). The −15% comes from the resolve cache alone: setup files and theirvi.mockpaths stop going to the main process before every file. With 3–11 workers the same cell (forks, nofsModuleCache, warm) gains −27% to −36%, so roughly half the gain there needs more than one worker. On main, the one-worker run (5.72 s) is barely slower than 11 workers (5.21 s).Existing apps
To see how the PR does on suites without mocking setup files: seven cells of existing apps, all
env: node, defaultmaxWorkers, warm (caches wiped, one untimed priming run, then timed runs, median). Main and PR alternate per cell. The two enterprise-monolithisolate: falsecells moved by −16% and +11% at 3 runs, so they were rerun with 10 runs per build, in four blocks (main, PR, main, PR) with caches wiped and re-primed for each block.Every cell is flat. The
isolate: truecontrols can't change by construction, since each file gets a fresh worker whose caches start empty, so their −3% and −4% are noise: the runs overlap (enterprise-monolith on main alone spans 5.85–7.12 s). Single runs of enterprise-monolith spread by up to ~20% (forks on main 3.53–4.28 s), which is why its 3-run medians moved. The PR neither helps nor hurts these suites; its gain shows up in the setup-mocks shape, where every file re-runs setup files that resolve and mock modules.late-graphs (loss case for keeping one snapshot per worker)
This also adds
late-graphs: 4 trivial test files that sort first, so each of the 4 workers starts with one, then 24 test files that share 12 chains of 250 modules, so the second dozen reuses chains the first dozen loaded, mostly on other workers. It targets vitest-dev/vitest#11761, which fetches the warm-modules snapshot once per worker: the server builds a snapshot from the requesting files' graphs, so a worker whose first file is trivial keeps a snapshot that misses the chains its later files reuse. vitest-dev/vitest#11760 (resolve cache only) is the control. Forks,isolate: false,vitest run, median of 3 runs.#11761 does fetch those chains module by module, but at this size it costs no measurable time. For comparison, on setup-mocks #11761 alone is −25…−26% with several workers and ~0 with one, and #11760 alone is −10…−11%.