Conversation
There was a problem hiding this comment.
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.
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
force-pushed
the
perf/rolldown-arena-purge
branch
from
October 2, 2026 20:00
2de2480 to
9738df9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.