perf(test): persist vitest transforms with fsModuleCache - #312
Merged
Merged
Conversation
vitest 5 reports that transforming the module graph took 51% of tracked time and is re-done on every run. fsModuleCache (new in 5.x, default false) persists transform results to disk and reuses them across reruns and separate vitest processes. Measured on this suite, 62 files / 892 tests: before (no cache) 21.62s tracked, transform 51%, 25.60s wall cold (cache empty) 20.87s tracked, transform 44% warm (cache warm) 18.91s tracked, transform 19%, 23.48s wall Transform drops from 51% to 19% of tracked time; wall time gains ~8%, since import cost now dominates rather than transform. The win is real but smaller than the 51% figure suggests -- transform overlaps other work. Cold runs are not penalised. Cache lands in node_modules/.vitest-cache (4.9M), the documented default. It sits inside node_modules so a reinstall invalidates it, and the existing node_modules/ entry in .gitignore already covers it -- no ignore change needed, and CI installs fresh so it is a no-op there.
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.
Follow-up to the vitest 5 bump (#285). vitest 5 added a diagnostic that fired on our first run against merged
main:fsModuleCacheis new in vitest 5 and defaults tofalse. It persists transformed modules to disk and reuses them across reruns and separate vitest processes.Measured, not assumed
62 files / 892 tests, same machine, back to back:
Transform drops from 51% to 19% of tracked time. Wall time only improves ~8% — the 51% figure overstates the practical win, because transform overlaps other work and
import(49% warm) now dominates. Worth taking, but it is not a halving. Cold runs are not penalised.Cache location
node_modules/.vitest-cache, 4.9M — the documented default. Two consequences, both checked:node_modules, so a reinstall invalidates it naturally. That is the upstream rationale for the default.node_modules/entry in.gitignorealready covers it, so no ignore change is needed.CI installs fresh every run, so this is a no-op there — the benefit is local reruns only.
Verification
pnpm test892/892 across cold and warm runspnpm run typecheckcleantest, perInlineConfigin the installed 5.0.1 types)