Repository navigation
perf(browser): reuse cached modules during vitest run - #11914
Merged
sheremet-va merged 7 commits intoNov 16, 2026
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Check `persistentContext` and the `preview` provider in every instance. - Revalidate the shims of factory mocks. - Turn off the run cache when orchestrator scripts are used. - Give an invalidated browser module a new url, as HMR does.
…w it mocks An instance that has not reported yet can still load modules (for example orchestrator scripts or the OpenTelemetry browser SDK), so ignoring it relied on an assumption that nothing enforces. Use the existing interception check instead, and drop the exclusion for orchestrator scripts that it needed.
magurotuna
marked this pull request as ready for review
November 9, 2026 05:54
This was referenced Nov 9, 2026
jrandolf
added a commit
to vase-ui/vase-ui
that referenced
this pull request
Nov 14, 2026
## Why Chromium jobs fail with `Browser connection was closed while running tests` and no failed case: 14 of 589 runs of `test-browser (chromium)` and `test-vue-floor` since the suite reached 354 test files, and none of the 1,041 runs before. None of 874 Firefox and WebKit runs failed this way. On Linux, Chromium keeps a block of shared memory for each module that a new test frame loads again, until a garbage collection frees it. A page that holds about 16,000 blocks loses its connections. Vitest collects the garbage after a test file only when less than 4 GB is free in the temporary folder, and a runner has about 85 GB free. ## What - `ci.yml` sets `VITEST_CHROMIUM_GC_DISK_THRESHOLD_GB` to `1000000` for all jobs. Vitest then collects the garbage of Chromium after each test file. Firefox and WebKit ignore the variable. - `VITEST_CHROMIUM_GC_FORCE` is not set. It only lets Vitest collect the garbage on other systems than Linux, and each CI job runs on Linux. - CONTRIBUTING.md gives the cause in "Where a test runs". "Tool versions" says what to check when the version of `vitest` changes, and when to remove the variable. - The Chromium job takes about 42 s longer (median 200 s to 242 s), and `test-vue-floor` takes about 34 s longer. The slowest Firefox shard and `check` take about 300 s, so a run of CI takes about as long as before. - Not used: serving the modules from the cache of the browser. It also removes the blocks, and it makes the job shorter. It needs a change of Vitest that is not released yet ([vitest-dev/vitest#11914](vitest-dev/vitest#11914)), or code of ours that depends on the internals of Vitest. ## Tests The number of blocks is the number of open `memfd` files of the busiest page process, read every 2 s. The runs "with the change" also set `VITEST_CHROMIUM_GC_FORCE`, which has no effect on Linux. - 50 runs of the Chromium job with the change: none failed. 24 runs of the same job without it, started at the same time: 3 failed with `Browser connection was closed`. - 38 runs without the change showed the number of blocks. Of the 33 runs that peaked below 14,500 blocks, none failed. Of the 5 that peaked above 15,400, 4 failed. - The same test with Vue 3.5.12 (`test-vue-floor`): 30 runs with the change, none failed with the error; 24 runs without it, 2 failed with it. With Vue 3.6.0-rc.15: 8 runs with the change, none; 16 without it, 1. - With the change, the highest number of blocks was 97 in 14 runs, and none failed. - With twice the test files (841), 2 of 6 runs without the change failed, and 0 of 6 with it. - Each variable alone, with the debug log of Vitest on, in a Chromium job of six test files: `VITEST_CHROMIUM_GC_DISK_THRESHOLD_GB` collected the garbage after 6 of 6 files, and `VITEST_CHROMIUM_GC_FORCE` after none.
sheremet-va
approved these changes
Nov 16, 2026
Member
|
Let's try it |
Merged
markharding
pushed a commit
to futo-org/Harbor
that referenced
this pull request
Nov 24, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [@vitest/browser-playwright](https://vitest.dev/config/browser/playwright) ([source](https://github.com/vitest-dev/vitest/tree/HEAD/packages/browser-playwright)) | [`5.1.0` → `5.1.1`](https://renovatebot.com/diffs/npm/@vitest%2fbrowser-playwright/5.1.0/5.1.1) |  |  | | [vitest](https://vitest.dev) ([source](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest)) | [`5.1.0` → `5.1.1`](https://renovatebot.com/diffs/npm/vitest/5.1.0/5.1.1) |  |  | --- >⚠️ **Warning** > > Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/2097) for more information. --- ### Release Notes <details> <summary>vitest-dev/vitest (@​vitest/browser-playwright)</summary> ### [`v5.1.1`](https://github.com/vitest-dev/vitest/releases/tag/v5.1.1) [Compare Source](vitest-dev/vitest@v5.1.0...v5.1.1) ##### 🚀 Features - **cache**: Add fs module cache env variables - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11859](vitest-dev/vitest#11859) [<samp>(708c0)</samp>](vitest-dev/vitest@708c05da0) ##### 🐞 Bug Fixes - Rerun on file changes after a config restart - by [@​magurotuna](https://github.com/magurotuna) in [#​11772](vitest-dev/vitest#11772) and [#​11829](vitest-dev/vitest#11829) [<samp>(289ca)</samp>](vitest-dev/vitest@289caab9c) - Avoid leaking the context expect - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11845](vitest-dev/vitest#11845) [<samp>(3c967)</samp>](vitest-dev/vitest@3c967a7b7) - Report fixture teardown errors once - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11857](vitest-dev/vitest#11857) [<samp>(6b167)</samp>](vitest-dev/vitest@6b167eb79) - Improve diffs for asymmetric matchers - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11855](vitest-dev/vitest#11855) [<samp>(86775)</samp>](vitest-dev/vitest@86775420f) - Apply --shard before the test run starts - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11846](vitest-dev/vitest#11846) [<samp>(e5c80)</samp>](vitest-dev/vitest@e5c80b775) - Reset local expect state between retries for `expect.assertions/hasAssertions` - by [@​hi-ogawa](https://github.com/hi-ogawa) and **Claude Opus 5.5** in [#​11900](vitest-dev/vitest#11900) [<samp>(50dcd)</samp>](vitest-dev/vitest@50dcdb373) - Sort test files before the seeded shuffle - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11926](vitest-dev/vitest#11926) [<samp>(3aa30)</samp>](vitest-dev/vitest@3aa3045a9) - Tear down fixture contexts one at a time - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11956](vitest-dev/vitest#11956) [<samp>(5712b)</samp>](vitest-dev/vitest@5712b5fd2) - Count merged errors in the error divider - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11955](vitest-dev/vitest#11955) [<samp>(4bc4f)</samp>](vitest-dev/vitest@4bc4f86e8) - Match `-` and `.` in `noExternal` wildcards - by [@​hi-ogawa](https://github.com/hi-ogawa) and **Claude Opus 5.5** in [#​11978](vitest-dev/vitest#11978) [<samp>(efba8)</samp>](vitest-dev/vitest@efba8cbfe) - Give each test attempt a new `signal` - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11998](vitest-dev/vitest#11998) [<samp>(77a30)</samp>](vitest-dev/vitest@77a306757) - Throw timeout error classes instead of Error - by [@​sheremet-va](https://github.com/sheremet-va) in [#​12003](vitest-dev/vitest#12003) [<samp>(9b874)</samp>](vitest-dev/vitest@9b87492f7) - **ast-collect**: - Only collect calls with a name argument - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11853](vitest-dev/vitest#11853) [<samp>(c015a)</samp>](vitest-dev/vitest@c015ad5a6) - **browser**: - Scale the iframe for preview without the UI - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11856](vitest-dev/vitest#11856) [<samp>(034d4)</samp>](vitest-dev/vitest@034d44e54) - Fix expect.element with `message` and remove redundant `[ERROR]` in trace steps - by [@​hi-ogawa](https://github.com/hi-ogawa) and **Claude Opus 5.5** in [#​11832](vitest-dev/vitest#11832) [<samp>(1d115)</samp>](vitest-dev/vitest@1d115dcc3) - **cache**: - Always leave a manifest to the fs module cache - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11858](vitest-dev/vitest#11858) [<samp>(1b238)</samp>](vitest-dev/vitest@1b2380c88) - Watch cached files outside the root - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11860](vitest-dev/vitest#11860) [<samp>(9c044)</samp>](vitest-dev/vitest@9c044db81) - Treat a removed cache file as a miss - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11861](vitest-dev/vitest#11861) [<samp>(f21f2)</samp>](vitest-dev/vitest@f21f224ba) - Allow cache hits in configureServer - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11927](vitest-dev/vitest#11927) [<samp>(a0dfc)</samp>](vitest-dev/vitest@a0dfc8b08) - **cli**: - Parse `--bail` correctly - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11896](vitest-dev/vitest#11896) [<samp>(4f91e)</samp>](vitest-dev/vitest@4f91e76af) - **coverage**: - Transform untested files with correct project - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11870](vitest-dev/vitest#11870) [<samp>(83298)</samp>](vitest-dev/vitest@832980392) - V8 to handle sub process script coverages separately - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11890](vitest-dev/vitest#11890) [<samp>(71ad4)</samp>](vitest-dev/vitest@71ad4dfa1) - Derive `ignoreNode` AST type from installed parser - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11958](vitest-dev/vitest#11958) [<samp>(cab34)</samp>](vitest-dev/vitest@cab34bb0e) - V8 to ignore more Vite's CJS import helpers - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11981](vitest-dev/vitest#11981) [<samp>(4e905)</samp>](vitest-dev/vitest@4e905a1ba) - **experimental**: - Skip ambiguous `expect.poll` trace steps in concurrent tests - by [@​hi-ogawa](https://github.com/hi-ogawa) and **Claude Opus 5.5** in [#​11869](vitest-dev/vitest#11869) [<samp>(f6ef4)</samp>](vitest-dev/vitest@f6ef4b0ef) - **mocker**: - Keep re-exports of hoisted imports - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11867](vitest-dev/vitest#11867) [<samp>(5f72c)</samp>](vitest-dev/vitest@5f72c3d0d) - **pool**: - Shutdown disconnected workers even when `testTimeout` is disabled - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11924](vitest-dev/vitest#11924) [<samp>(97911)</samp>](vitest-dev/vitest@979118a70) - Terminate stuck orphaned forks workers - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11939](vitest-dev/vitest#11939) [<samp>(47c87)</samp>](vitest-dev/vitest@47c87ebb5) - `isolate: false` to not re-use workers that failed to start - by [@​AriPerkkio](https://github.com/AriPerkkio) in [#​11953](vitest-dev/vitest#11953) [<samp>(7e672)</samp>](vitest-dev/vitest@7e67234a9) - **reporter**: - Report crashed test files as failed in json - by [@​magurotuna](https://github.com/magurotuna) in [#​11965](vitest-dev/vitest#11965) [<samp>(47fb9)</samp>](vitest-dev/vitest@47fb992ca) - **spy**: - Use primordials to allow spying on builtins - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11837](vitest-dev/vitest#11837) [<samp>(d951e)</samp>](vitest-dev/vitest@d951e63d3) - **typecheck**: - Add env var to hide experimental warning - by [@​aliamanatali](https://github.com/aliamanatali) in [#​11840](vitest-dev/vitest#11840) [<samp>(5a69e)</samp>](vitest-dev/vitest@5a69e4396) - Kill the checker process tree on windows - by [@​sheremet-va](https://github.com/sheremet-va) in [#​11850](vitest-dev/vitest#11850) [<samp>(1fa69)</samp>](vitest-dev/vitest@1fa69e09b) - **vitest**: - Allow assigning to import.meta.env - by [@​aliamanatali](https://github.com/aliamanatali) in [#​11841](vitest-dev/vitest#11841) [<samp>(9fd1f)</samp>](vitest-dev/vitest@9fd1f22a4) ##### 🏎 Performance - Send source maps to workers as a string - by [@​maschwenk](https://github.com/maschwenk) in [#​11750](vitest-dev/vitest#11750) [<samp>(485cd)</samp>](vitest-dev/vitest@485cd627d) - Resolve CLI file filters once instead of per test file - by [@​maschwenk](https://github.com/maschwenk) in [#​11935](vitest-dev/vitest#11935) [<samp>(96a90)</samp>](vitest-dev/vitest@96a9032af) - **browser**: Reuse cached modules during vitest run - by [@​magurotuna](https://github.com/magurotuna) in [#​11914](vitest-dev/vitest#11914) [<samp>(0c502)</samp>](vitest-dev/vitest@0c502bc72) ##### [View changes on GitHub](vitest-dev/vitest@v5.1.0...v5.1.1) </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4yNTIuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjI1Mi4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/2478 Reviewed-by: Thomas de Zeeuw <thomas@futo.org>
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.
In browser mode, every test file runs in a new tester iframe. Vite serves source modules with
Cache-Control: no-cache, so the iframe revalidates every module that it imports (one304per module per test file). But modules don't change duringvitest run, so we can let the iframes reuse the cached modules, in the same way #10729 does for Vitest's own assets.The cache stays off in these cases:
persistentContextoptionpreviewprovider is usedvi.mock(path, factory)), because their exports can change between test filesReruns from the API
With this change, the browser takes modules from its cache without asking the server. So
vitest.invalidateFile()alone no longer makes a long-running instance withwatch: falseget the new code. Now, ifinvalidateFile()is called whenwatchisfalse, the next run opens new browser contexts, which start with an empty cache. Watch mode doesn't change.Perf
Wall time, Chromium, 3 workers (median of 5 to 7 paired runs):
Note that with Playwright's Firefox, a large suite gets slower with this change, because of a bug in Playwright's Firefox driver (microsoft/playwright#43990).
Question
#10729 turned on the cache for Vitest's own assets only. I wasn't able to find a reason to exclude project modules. If there's concern with doing so, we can make this opt-in.