Skip to content

perf(test): persist vitest transforms with fsModuleCache - #312

Merged
stackbilt-admin merged 1 commit into
mainfrom
chore/vitest-fs-module-cache
Sep 20, 2026
Merged

stackbilt-admin merged 1 commit into
mainfrom
chore/vitest-fs-module-cache

Conversation

@stackbilt-admin

Copy link
Copy Markdown
Member

Follow-up to the vitest 5 bump (#285). vitest 5 added a diagnostic that fired on our first run against merged main:

Transform  transforming modules took 66.20s · 51% of tracked time, re-done on every run
           persist transforms across runs with fsModuleCache: true

fsModuleCache is new in vitest 5 and defaults to false. 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:

run tracked duration transform share wall
before (no cache) 21.62s 51% 25.60s
cold (cache emptied) 20.87s 44%
warm 18.91s 19% 23.48s

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:

  • It sits inside node_modules, so a reinstall invalidates it naturally. That is the upstream rationale for the default.
  • The existing node_modules/ entry in .gitignore already 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 test 892/892 across cold and warm runs
  • pnpm run typecheck clean
  • No unknown-option or deprecation warning from vitest, confirming the key is valid where it is placed (inside test, per InlineConfig in the installed 5.0.1 types)

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.
@stackbilt-admin
stackbilt-admin merged commit 41a90b5 into main Sep 20, 2026
5 checks passed
@stackbilt-admin
stackbilt-admin deleted the chore/vitest-fs-module-cache branch September 20, 2026 11:51
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