#10393·rolldown

Build peak memory scales with module count; lazyBarrel is off-by-default and doesn't defer `export *` barrels

Author: kHorozhanovCreated Jul 22, 2026Updated Sep 29, 2026
Labelsscope: memory

What problem does this address?

For a moderate module graph, rolldown's peak build RSS is reached during the scan phase — every module's AST (bumpalo arena) is allocated and held — and it is several times esbuild's for the same graph, widening as the graph grows. On real apps this OOMs builds that webpack/turbopack/esbuild handle: a ~2,500-module Next.js App Router build reaches ~9–10 GB and is OS-killed on 16 GB.

Minimal, dependency-free reproduction with a bundler baseline and phase-boundary peak-RSS traces: https://github.com/kHorozhanov/rolldown-build-memory (npm i && npm run matrix).

1. Per-module retention vs esbuild (identical reachable graph)

N esbuild rolldown ratio
1,000 55 MB 137 MB 2.5×
4,000 60 MB 297 MB 5.0×
8,000 65 MB 493 MB 7.6×

esbuild is ~flat; rolldown adds ~55 MB per 1,000 trivial modules and the gap widens. The phase trace shows post-scan is already the peak — every module's AST is live at once. This looks like the user-facing side of the AST-arena retention in #9516 / the footprint gap in #9330. Is any of the arena right-sizing / per-module release / streaming follow-up planned? The repro suggests it's O(modules) with a large constant, not just the #9516 fixture.

2. experimental.lazyBarrel — the one lever that lowers the scan peak

Deferring loading of a side-effect-free barrel's unused members is the only thing that reduces the peak (the ASTs are never allocated):

N=8000, used=50, sideEffects:false barrel post-scan peak
named barrel, lazyBarrel off 599 MB
named barrel, lazyBarrel on 211 MB
star (export *) barrel, lazyBarrel on (before) 599 MB — no effect
star barrel, lazyBarrel on (with #PR) 196 MB

Two gaps, one addressed here:

  • export * was not deferrable — BarrelInfo::take_needed_records attributed any name not in named to all star records, loading every target. The date-fns main entry is exactly this (245 export * re-exports). I've opened a PR implementing on-demand star probing for sideEffects:false barrels: ~649 MB → ~196 MB on the repro, byte-identical output, suite green (one documented ambiguity caveat).
  • Off by default, and requires an explicit sideEffects:false — a structurally-pure re-export barrel without the declaration isn't deferred. Would you consider defaulting it on for eligible barrels, or documenting it? It's a large, safe win that's currently undiscoverable.

Repro, phase traces, and full per-lever measurements in the linked repo. Happy to profile specific runs.