Skip to content

Astro build runs out of memory during content sync for large Starlight docs site with heavy KaTeX #17301

Description

@integrable

Astro Info

Astro                    v7.0.6
Vite                     v8.1.3
Node                     v24.18.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/starlight (v0.41.3)

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have a large Starlight documentation site with many Markdown/MDX docs containing heavy KaTeX/math content.

The build runs out of memory during Astro’s content sync phase, before page generation starts.

The minimal reproduction repo is https://github.com/integrable/astrov7/

The failure happens after [content] Syncing content and then Node/V8 eventually aborts with:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

This appears to be a scalability issue in Astro’s content layer for renderable Markdown/MDX entries. My current understanding is that Astro’s glob() content loader eagerly renders Markdown/MDX entries and stores the rendered output in the global content data store. For Starlight docs pages with heavy KaTeX, the rendered HTML is much larger than the source Markdown, so syncing content can consume several GB of heap and eventually crash.

The KaTeX warnings printed before the crash do not seem to be the direct cause; they are warnings, and the process continues until memory is exhausted.

Steps to Reproduce:

git clone https://github.com/integrable/astrov7.git
cd astrov7
npm ci
rm -rf .astro dist node_modules/.astro
npm run build

Actual Result:

The build starts syncing content:

15:52:45 [content] Syncing content

Then several KaTeX warnings are printed, for example:

LaTeX-incompatible input and strict mode is set to 'warn': In LaTeX, \ or \newline does nothing in display mode [newLineInDisplayMode]

After several minutes, Node runs out of memory:

<--- Last few GCs --->

[93872:0x8b540c000]   178849 ms: Scavenge (interleaved) 4093.3 (4108.7) -> 4093.1 (4109.7) MB, pooled: 0 MB, 3.96 / 0.00 ms  (average mu = 0.288, current mu = 0.234) allocation failure; 
[93872:0x8b540c000]   179724 ms: Mark-Compact (reduce) 4094.0 (4109.7) -> 4093.9 (4108.2) MB, pooled: 0 MB, 630.04 / 0.00 ms  (+ 9.1 ms in 14 steps since start of marking, biggest step 5.0 ms, walltime since start of marking 647 ms) (average mu = 0.286, c
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

zsh: abort npm run build

Related issue:

This is related to, but different from, the previous large content-store dev issue:

#17220

That issue was about dev mode returning empty collections when importing a large content data-store virtual module. This report is about build/content sync exhausting memory before page generation because the content store becomes too large when rendered Markdown/KaTeX output is eagerly retained.

What's the expected result?

Astro should be able to build a large static Starlight docs site with heavy Markdown/KaTeX content without exhausting the Node heap during content sync.

More specifically, Astro/Starlight should not need to eagerly render and retain the rendered HTML for every docs page in the global content data store before page generation.

A scalable behavior would be one of:

  1. Astro exposes an official deferred-render option for renderable Markdown/MDX content entries, for example glob({ deferRender: true }) or similar.
  2. Starlight uses such a deferred-render mode for the docs collection.
  3. Astro avoids storing full rendered HTML for every renderable content entry when it is not needed for collection querying.

Workable local patches are as follows:

astro+7.0.6.patch
@astrojs+starlight+0.41.3.patch

Link to Minimal Reproducible Example

https://github.com/integrable/astrov7

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix verifiedReporter confirmed the triage bot fix works

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions