Skip to content

perf: keep resolve and warm snapshot answers per worker - #11752

Open
vjeux wants to merge 1 commit into
vitest-dev:mainfrom
vjeux:perf-non-isolated-worker-rpc
Open

vjeux wants to merge 1 commit into
vitest-dev:mainfrom
vjeux:perf-non-isolated-worker-rpc

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026

Copy link
Copy Markdown

Prepared by @vjeux's coding agent at his request; he asked for this to be sent and follows up here himself. cc @cpojer

A worker with isolate: false asks the main process twice per run request for things it already knows: the fetchWarmModules snapshot (once per request, so once per file when maxWorkers > 1), and every resolve, including the vi.mock paths of the setup files that run again before each test file. With many workers, each round-trip waits behind the others' calls on the main thread.

Repro with counts and timings: https://github.com/vjeux/vitest-warm-rpc-repro. On vitest 5.0.5 with 32 workers, 2,000 test files over a 3,000-module tree and 6 setup files: 16.8 s stock, ~12.6 s with either answer kept, 6.3 s with both. A 6,600-file suite went from 96 s to 58 s with the same two changes applied as local shims.

This keeps both answers for the worker's life: the snapshot is asked once per worker, and a (specifier, importer, environment) is resolved once (a rejected resolution is asked again). Watch mode, and a run request that invalidates files, start over.

The test runs three files on two non-isolated workers and reads the worker's rpc calls through a custom runner: before this change the worker that ran two files asked the snapshot twice and repeated two resolutions; after it, once and none.

A non-isolated worker asked the main process on every run request for
the warm-modules snapshot and for every resolution again, including the
`vi.mock` paths of setup files that run before each test file. Both
answers are kept for the worker's life; watch mode and a request that
invalidates files start over.
@github-actions

Copy link
Copy Markdown

Hello @vjeux. Thank you for taking the time to contribute!

Unfortunately, the team accepts pull requests only from maintainers, from anyone who contributed before, from approved contributors, or for issues with the approved label, so this pull request was closed automatically. We are sorry about that, it is not a judgement of your work. The number of pull requests grew beyond what the team can review, and this policy gives maintainers the space to triage and prioritize issues at their own pace.

If there is no issue for this change yet, please open one to discuss it with the team first. Your changes are not lost: a maintainer can reopen this pull request if the team decides to go forward with it. See our pull request policy for more context.

@github-actions github-actions Bot closed this Oct 26, 2026
@netlify

netlify Bot commented Oct 26, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6fbc6ae
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6adfd5b48a3d782c41f0ae20
😎 Deploy Preview https://deploy-preview-11752--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa

Copy link
Copy Markdown
Collaborator

Thanks for the PR. I ran benchmark on vitest-dev/benchmarks#2. Caching warmModules and resolveId makes sense but the workload that benefits from the optimization seems narrow as expected. Also two ideas seem independent, so I'll try to split into two PR to see the effect better.

This branch has not been deployed

No deployments
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.

2 participants