Skip to content

perf(ssr): pre-transform static imports by default - #24094

Open
hood wants to merge 1 commit into
vitejs:mainfrom
hood:perf/ssr-pretransform
Open

hood wants to merge 1 commit into
vitejs:mainfrom
hood:perf/ssr-pretransform

Conversation

@hood

@hood hood commented Nov 13, 2026

Copy link
Copy Markdown

defaults dev.preTransformRequests to true for every environment, not just client. cold SSR loads in dev go ~2x faster.

fixes #24093

why

ssr-transformed modules await their imports one by one, so with pre-transform off every module starts resolve/load/transform only after the previous one is done. turning it on lets importAnalysis warm up static imports while the runner is still busy upstream, same as on the client. Vite 5 did this for ssr already, it got lost in #16471 (#19272 noticed it too). details and history in the issue.

externalized imports return before the warmup call in importAnalysis, so nothing extra in node_modules gets transformed.

numbers

cold runner.import() of a seeded react+ts app, on a default config, comparing upstream f89888822 vs this branch, 7 interleaved runs, mac M1 Pro, nodejs v26:

app upstream median (min-max) this PR median (min-max) wall server CPU peak RSS
1652 modules 3176 ms (3051-3477) 1499 ms (1416-1557) -53% 3974 -> 3405 ms 489 -> 568 MB
332 modules 758 ms (708-827) 378 ms (352-420) -50% 1255 -> 1139 ms 257 -> 278 MB

repro on published 8.3.8 by flipping the option: https://github.com/hood/vite-ssr-pretransform-repro

npm i && npm run gen && npm run bench

RSS goes up a bit, more transforms in flight at once.

things worth a look

  • custom environments flip to true too (snapshot updated). they load through the same module runner, so same win, but lmk if you'd rather keep it to consumer === 'server'.
  • modules that are imported but never executed (vitest mocks, see How to disable Pre-transform error log? vitest-dev/vitest#7345) now get transformed and can log a Pre-transform error, same as the client env does today. opt out is server.preTransformRequests: false. vitest might want to set it explicitly.

tests

  • pnpm test-unit, pnpm test-serve, pnpm test-build on this branch
  • all ssr playgrounds pass (ssr, ssr-html, hmr-ssr, environment-react-ssr, ssr-deps, ssr-webworker, ...), no Pre-transform error logs. ssr-html already asserts on that
  • no new test, the existing preTransformRequests config test covers the default

AI disclosure: helped myself w/ Claude Code for profiling and digging through git history.

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.

SSR dev doesn't pre-transform imports by default since Vite 6, cold SSR loads are ~2x slower

1 participant