You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Start: import protection keeps a parsed AST per module in dev (hundreds of MB in large apps) #8614
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.
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.
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-start 1.169.1 and @tanstack/start-plugin-core 1.171.19.
Read-only live-object inspection through the Node inspector found two import-protection environment states whose transformResultCache values retained:
1,390 distinct transform results, all with both parsedAst and analysis (about 4.59 million source characters).
1,459 distinct transform results, all with both parsedAst and analysis (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 Node objects, 1.99 million SourceLocation objects, 2.76 million Position objects, 366,131 NodePath objects and 204,913 TraversalContext objects.
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-core 1.171.55 tarball: buildImportAnalysis still places ast in the cached analysis. The focused fix in #8682 would be valuable for memory-constrained development machines while keeping import protection enabled.
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…