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
@clydin
clydin force-pushed the perf/rolldown-arena-purge branch from 2de2480 to 9738df9 Compare October 2, 2026 20:00
@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 5, 2026

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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 9738df9 to 34c2a22 Compare October 5, 2026 14:00
@clydin clydin added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker 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.

2 participants