Description
Which project does this relate to?
Start
Describe the bug
In development, import protection keeps one parsed AST for every module it analyses, for as long as the dev server runs. The analysis of each module is cached on its transform result in a per-environment cache. That cached analysis holds the AST (ImportAnalysis.ast, earlier TransformResult.parsedAst). The AST is only needed while building the analysis and, rarely, to find the usage position of a violation, but it is retained for every module.
In our app (Solid Start) this was about 145 MB of live heap per dev server, and we run several servers at once. In the reproducer below, 1,500 generated modules (about 6 MB of source) leave 474 MB of live heap with import protection on and 158 MB with it off, after one page load and a forced GC.
Complete minimal reproducer
https://github.com/jav-ed/start-import-protection-memory-repro
Steps to reproduce the bug
git clonethe repository and runnpm install- Run
npm run measure(it generates the modules, starts the dev server with import protection on and then off, loads/once and prints the live heap after a forced GC) - Compare the two numbers
Expected behavior
Import protection should not keep memory proportional to the size of every analysed module. With the AST dropped from the cached analysis (and parsed again only when a violation needs its usage position), the same reproducer leaves 173 MB, within 15 MB of having import protection off. I can inshallah share the patch, with a test, if that is useful.
Platform
- Router / Start Version: @tanstack/react-start 1.168.60, @tanstack/start-plugin-core 1.171.49
- OS: Linux x64
- Browser: not relevant (server memory)
- Bundler: vite
- Bundler Version: 7.3.6 (we see the same on 8.3.2)
Additional context
Node 26.7.0. The measurements and the reproducer were prepared with the help of Claude Code and verified by running them.
Activity
avloss commentedon Nov 3, 2026
Confirmed in a React Start application on an 8 GB Apple Silicon Mac, macOS 26.6.2, Node 26.11.1, Vite 8.3.4,
@tanstack/react-start1.169.1 and@tanstack/start-plugin-core1.171.19.Read-only live-object inspection through the Node inspector found two import-protection environment states whose
transformResultCachevalues retained:parsedAstandanalysis(about 4.59 million source characters).parsedAstandanalysis(about 5.75 million source characters).After explicit garbage collection, the whole process still had 1,130,334,112 bytes of used JS heap. The live object inventory included about 2.00 million Babel
Nodeobjects, 1.99 millionSourceLocationobjects, 2.76 millionPositionobjects, 366,131NodePathobjects and 204,913TraversalContextobjects.These are whole-process heap/object measurements, not retained-byte attribution solely to import protection; no local on/off A/B was performed. The cache inspection directly confirms the retention mechanism described here.
Also checked the published
@tanstack/start-plugin-core1.171.55 tarball:buildImportAnalysisstill placesastin the cached analysis. The focused fix in #8682 would be valuable for memory-constrained development machines while keeping import protection enabled.fix(start-plugin-core): drop parsed AST after import analysis to avoi…