Skip to content

perf(@angular/build): immediately purge freed rolldown arena memory - #34245

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/rolldown-arena-purge
Open

clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/rolldown-arena-purge

Conversation

@clydin

@clydin clydin commented Oct 2, 2026

Copy link
Copy Markdown
Member

Rolldown's native binding statically links mimalloc v3, which defaults to a 4-second arena purge delay (MIMALLOC_PURGE_DELAY=1000 * MIMALLOC_ARENA_PURGE_MULT=4) and only executes scheduled purges cooperatively during subsequent allocations. In single-run CLI builds where Rolldown is not invoked again after bundling completes, non-zero purge delays prevent freed arena pages from being returned to the OS, increasing peak RSS when subsequent post-bundle stages run.

Introduce a shared loadRolldown() helper used by both the application chunk optimizer and the library builder that temporarily sets MIMALLOC_PURGE_DELAY=0 (when not already configured in the environment) while loading Rolldown's native binding so mimalloc caches a 0ms purge delay without leaving the variable set in process.env.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Oct 2, 2026
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Oct 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a loadRolldown utility to dynamically load the rolldown module while temporarily setting MIMALLOC_PURGE_DELAY=0. This configures the embedded mimalloc allocator to immediately purge freed arena memory, reducing peak RSS in single-run CLI builds. The utility is integrated into the chunk optimizer and library bundler, accompanied by unit tests. Feedback recommends resetting the cached rolldownPromise to undefined upon import failure to allow recovery in long-running processes like watch mode.

Comment thread packages/angular/build/src/utils/load-rolldown.ts
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 2, 2026
@clydin
clydin requested a review from alan-agius4 October 2, 2026 15:12
Rolldown's native binding statically links mimalloc v3, which defaults to a 4-second arena purge delay (MIMALLOC_PURGE_DELAY=1000 * MIMALLOC_ARENA_PURGE_MULT=4) and only executes scheduled purges cooperatively during subsequent allocations. In single-run CLI builds where Rolldown is not invoked again after bundling completes, non-zero purge delays prevent freed arena pages from being returned to the OS, increasing peak RSS when subsequent post-bundle stages run.

Introduce a shared loadRolldown() helper used by both the application chunk optimizer and the library builder that temporarily sets MIMALLOC_PURGE_DELAY=0 (when not already configured in the environment) while loading Rolldown's native binding so mimalloc caches a 0ms purge delay without leaving the variable set in process.env.
@clydin
clydin force-pushed the perf/rolldown-arena-purge branch from 2de2480 to 9738df9 Compare October 2, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build area: performance Issues related to performance target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant