Skip to content

Start: import protection keeps a parsed AST per module in dev (hundreds of MB in large apps) #8614

Description

@jav-ed

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

  1. git clone the repository and run npm install
  2. 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)
  3. 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

  1. avloss commented on Nov 3, 2026

    @avloss

    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.

  2. added a commit that references this issue on Nov 4, 2026
    504d356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions