Repository navigation
perf(binding): return memory to the OS once rolldown is idle - #11655
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
ea13de0 to
eeb4d50
Compare
…#11769) Closes #10984 Related to #11655 `BindingBundler` kept the handle of every build until `close()`. Each handle pins its build's `PluginDriver`, so every `generate()` on the same bundle kept one more build's modules in memory. > [!WARNING] > The plugin timings report adds up a build's clocks when the next build starts. A build writes its clocks only when it ends, so if builds on the same bundle overlap, a build that is still running is left out.
## Summary Cuts the memory the three local Vite dev servers (`client/dashboard`, `client/admin`, `dev-idp-dashboard`) hold after a page load by roughly 30%. - **Start scripts**: `start:dashboard`, `start:admin-dashboard` and `start:dev-idp-dashboard` now set allocator, worker-thread and V8 heap limits before Node starts. Each one yields to a value already in the environment, so `mise.local.toml` can override it. - **Vite 8.3.5 → 8.3.7** (Rolldown 1.2.15 → 1.2.18) for the dashboard, admin and dev-idp-dashboard workspaces. 8.3.8 is newer than the repo's `minimumReleaseAge` allows, so the catalog stops at `^8.3.7`. - **`Icon` component**: looks icons up on the `lucide-react` namespace instead of `lucide-react/dynamicIconImports`. A new test checks that every icon name still resolves. ### Savings RSS in MB after loading the app's entry page and forcing a GC, measured on aarch64 Linux with a warm dependency cache: | Dev server | Before | After | |---|---|---| | dashboard | 1,246 | 872 | | admin | 568 | 394 | | dev-idp-dashboard | ~520 | ~400 | | **Total** | **~2,330** | **~1,670** | Idle, before any page load, the three drop from about 900 MB to about 660 MB combined. The `Icon` change also removes about 1,750 requests from every dashboard page load in dev (8,372 modules → 6,614) and cuts the pre-bundled dependency cache from 4,587 files to 1,071. The production build is unchanged in total size; its lucide chunk shrinks from 720 KB to 637 KB. ## Motivation The three Vite dev servers were about half of the memory a worktree's local stack uses, and several worktrees often run at once. Most of what they held was not live data: - V8 let the heap grow towards its default ~4 GB limit before collecting, although the dashboard server keeps only about 370 MB live. - Rolldown's allocator and glibc's per-thread arenas kept freed memory instead of returning it, spread over 46 threads. - Importing `dynamicIconImports` next to the main `lucide-react` entry made Vite pre-bundle every icon as its own file. Production already ships all of lucide in one chunk, so the lazy per-icon imports saved nothing there. The flags have to be in the environment before Node starts, which is why they are in the start scripts and not in `vite.config.ts`. The flags, not the Vite upgrade, account for the measured memory saving: 8.3.7 alone made no measurable difference, but it honours CPU limits when sizing worker threads and trims module sourcemaps. Not addressed here: a dev server that pre-bundles dependencies itself on a cold cache still keeps about 1.3 GB (dashboard) until its next restart. That is an upstream Rolldown issue (rolldown/rolldown#9330) with a fix in draft (rolldown/rolldown#11655). ## Gutternote review steps No intended visual change. Icons rendered through the shared `Icon` component are now present on first paint instead of appearing a moment later. 1. Log in and stay on the first project page that loads; any page with buttons or cards will do. 2. Expect the icons inside buttons, cards, alerts and inputs to look as before, with no empty gap while the page loads. Shared change: `Icon` is used by `Button`, `Card`, `Alert`, `Input`, `Link` and `MoreActions`, so any page works as a spot check. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Cuts the memory the three local Vite dev servers (`client/dashboard`, `client/admin`, `dev-idp-dashboard`) hold after a page load by roughly 30%, from about 2.3 GB to about 1.7 GB combined. - A shared script sourced by the three start tasks sets allocator, worker-pool, and V8 heap limits before Node starts. Each value yields to an existing environment variable so `mise.local.toml` can override it. - Vite is bumped from 8.3.5 to 8.3.7 (Rolldown 1.2.15 → 1.2.18) in the three dashboard workspaces. The version stops at `^8.3.7` because 8.3.8 is newer than the repo's `minimumReleaseAge` allows. - The `Icon` component now resolves icon names directly on the `lucide-react` namespace instead of through `lucide-react/dynamicIconImports`, and a new test verifies every icon name still resolves. - The MCP consent‑tools bundle (`server/internal/mcp/consent_assets/consent-tools.js`) was rebuilt to match the new Vite. **Side effects** - Icons rendered through the shared `Icon` component appear immediately instead of popping in a moment after page load. - Dashboard page loads in dev drop about 1,750 requests (8,372 modules → 6,614), and the pre-bundled dependency cache shrinks from 4,587 files to 1,071. - The `Icon` change has no effect on production total size; the lucide chunk shrinks from 720 KB to 637 KB. <sup>Written for commit 0199251. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/speakeasy-api/gram/pull/9187?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/speakeasy-api/gram/9187?returnTo=https%3A%2F%2Fgithub.com%2Fspeakeasy-api%2Fgram%2Fpull%2F9187&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. --> <!-- gram-preview-bot --> --- ## 🚀 Preview Environment (PR speakeasy-api#9187) **Preview URL:** https://pr-9187.dev.getgram.ai | Component | Status | Details | Updated (UTC) | |-----------|--------|---------|---------------| | ✅ Database | Ready | Existing database reused | 2026-11-17 14:53:27. | | ✅ Images | Available | Container images ready | 2026-11-17 14:54:36. | <!-- state:eyJEYXRhYmFzZSI6eyJlbW9qaSI6IuKchSIsInN0YXR1cyI6IlJlYWR5IiwiZGV0YWlscyI6IkV4aXN0aW5nIGRhdGFiYXNlIHJldXNlZCIsInRpbWUiOiIyMDI2LTExLTE3IDE0OjUzOjI3LiJ9LCJJbWFnZXMiOnsiZW1vamkiOiLinIUiLCJzdGF0dXMiOiJBdmFpbGFibGUiLCJkZXRhaWxzIjoiQ29udGFpbmVyIGltYWdlcyByZWFkeSIsInRpbWUiOiIyMDI2LTExLTE3IDE0OjU0OjM2LiJ9fQo= --> <sub>Gram Preview Bot</sub> <!-- /gram-preview-bot --> --------- Co-authored-by: Claude Fable 5.2 <[email protected]>
Related to #11143 Drop the sourcemaps of each rendered module once its chunk is joined. Each module in the output kept its sourcemaps, but nothing reads them after the join, because the chunk's own map already covers them. They stayed alive through minification, and after the build for as long as JS held the output. This part is split out from #11655. ## Memory Rust heap on macOS arm64, counted by the tracking allocator in a debug binding. The input is three.js x10, and each value is the range of three interleaved runs. ### Idle, while JS holds the output after the build | Case | main | This PR | |---|---|---| | `sourcemap: true` | 118.3 to 118.4 MB | 80.8 to 80.9 MB | | `sourcemap: false` | 24.4 to 24.6 MB | 24.3 to 24.6 MB | ### Peak during the build | Case | main | This PR | |---|---|---| | `sourcemap` and `minify` | 520.0 to 520.4 MB | 482.0 to 482.7 MB | | `sourcemap` and `minify`, split into 12 chunks | 522.7 to 524.9 MB | 487.0 to 488.2 MB | | `sourcemap` only | 348.1 to 348.7 MB | 347.8 to 348.4 MB | | neither | 347.7 to 348.5 MB | 347.7 to 348.4 MB | The peak only drops with `minify`, which runs after every chunk is joined. Without it, the peak comes earlier, before these maps exist. ### Peak memory in Node Peak process memory (`phys_footprint`) with the release binding, five interleaved runs. | Case | main | This PR | |---|---|---| | One build, `sourcemap` and `minify` | 703 to 719 MB | 692 to 714 MB | | One build, `sourcemap` only | 522 to 526 MB | 521 to 528 MB | | One build, neither | 415 to 420 MB | 417 to 423 MB | | Five builds holding all outputs, `sourcemap` | 1227 to 1257 MB | 1066 to 1085 MB | | Five builds holding all outputs, `sourcemap` and `minify` | 1548 to 1634 MB | 1420 to 1465 MB | The effect is only clear in very large projects.
eeb4d50 to
a3670cc
Compare
|
Another data point: this PR's CI build (727aecd, the Setup: Vite 8.3.8 dev server (not bundled dev), React app. The dependency optimizer pre-bundles 66 deps (26 MB of output). Linux x64, 32 cores, Node 26.12.1. RSS is Vite dev server, cold start (no
rolldown alone, same 66 entries,
Thread count: with 1.2.19, the retained memory scales with the thread pool. Limiting the process with a systemd Bundled dev ( |
727aecd to
1705c69
Compare
1705c69 to
b990ba3
Compare
b990ba3 to
1bedfad
Compare
Set the allocator options with `mi_option_set_default`. It keeps a value set through a `MIMALLOC_*` environment variable, whatever the letter case of its name.
…ract release_arc helper (#11855)" (#11898) Related to #11899 This reverts #11855, which is not in any release yet. #11655 fixes the related memory problem. It returns freed memory to the OS once rolldown is idle, and lets V8 GC track the native memory that an output holds. #11855 only adds an API to drop native data early. It does not fix the actual problem, and it is not automatic, because every caller has to know when to drop. On wasm, #11655 does not help, because the GC does not see Wasm memory. That case needs a better solution than calling `dropInner()` from JS after every hook. #11899 is that solution. Plugin contexts hold their build weakly, so the build frees its data when it finishes, and on wasm JS gets plain data instead of native objects. No class needs `dropInner()`, and a context that a plugin keeps still works for the rest of its build, as in Rollup. #11899 has the measurements and a comparison with Rollup, main and #10268. #10268 calls these methods, so it needs to follow this change.
Related to #6121, #9330 and #10985 `freeExternalMemory` from `rolldown/experimental` drops the Rust data behind an output, but the process does not get the memory back. mimalloc keeps the freed pages with the threads that allocated them, so the memory stays resident and is only reused by a later build in the same process. #9330 and #10985 both report `freed: true` with no change in memory. On main, after one three.js x10 build with sourcemaps, the call returns `{ freed: true }` and the process stays at 818 MB 3 s later, the same as when the output is kept. The underlying problem is fixed by #11655. It returns the memory to the OS once rolldown is idle, and lets V8 see how much native memory an output holds, so dropping the output is enough. Neither Vite nor any third-party project uses `freeExternalMemory`. On GitHub, the only results are copies of rolldown's own type files and one project that stubs it as a no-op. This also removes `dropInner()`, `ExternalMemoryStatus`, and the `Option` around the data of `BindingOutputChunk` and `BindingOutputAsset`, which only existed for this API.
# Conflicts: # crates/rolldown_binding/src/types/binding_output_asset.rs # crates/rolldown_binding/src/types/binding_output_chunk.rs # packages/rolldown/src/binding.d.cts # packages/rolldown/src/rolldown-binding.wasi.d.cts
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
/ecosystem-ci run |
|
Thanks for measuring. I tried to reproduce the slower builds on the current head (6e224c1), but I couldn't. Setup: a Linux arm64 VM (OrbStack, kernel 7.2.12, 13 cores, 15 GB) with THP
With a 2 s pause, every build starts after a round. RssAnon is 164 MB before each build instead of 874 MB. The builds still take the same time as with With a 600 ms pause, there is no round between builds anymore. Since 146eed4 a notification only sets a flag, and a round starts 0.5 to 1 s after the last one. The memory still drops after the last build. On a large project it looks the same. These are 4 Vite builds of lobehub in one process on macOS, 2 processes per row, with mimalloc memory:
So here a build after a round costs about as much as a cold build, which is the expected trade-off, and it doesn't show in the build time. The 1.51 s of system CPU per build you saw is far more than the 7 to 10 ms here. Could you share your kernel version and THP settings ( |
You're right that the description was too strong about the overlap in watch mode. A cleanup never starts while a build runs, but a build that starts during a cleanup does not wait for it. I updated the description and listed the overlap under Known gaps. I measured your watch case on the current head (6e224c1). rolldown's Linux arm64 VM (OrbStack, kernel 7.2.12), THP
macOS, with mimalloc memory:
The rebuild times don't change with the delay on either machine. The default 500 ms costs about 6% more CPU on macOS with an edit every 3 s, and the difference on Linux is within noise. That is far from the 59.4 s against 38.2 s you measured. So I kept the 500 ms default. rolldown's own watch mode is probably not used much, and so far I don't see a clear performance cost. A longer delay keeps the memory of every rebuild while the user edits, which raises the peak memory of a dev session, and the CPU it saves is small here. Also, since 146eed4 a notification only sets a flag, so a cleanup already starts 0.5 to 1 s after the last one, not exactly at 500 ms. |
That The settings are only defaults, so the |
hyfdev
left a comment
There was a problem hiding this comment.
The slowdown on 6e224c1 comes from THP on fragmented memory.
- Our machine: x86_64, kernel 6.18.58, THP
enabled=always,defrag=madvise, khugepageddefrag=1. - mimalloc marks its arenas
MADV_HUGEPAGE. Underdefrag=madvise, each huge-page fault after a cleanup compacts synchronously. - After 7 days of uptime, 14 GB was free but held only about 100 contiguous 2 MiB blocks. Almost all compactions fail.
- API builds with a 2 s pause: 675–741 ms, against 606–611 ms with
off. - Watch mode, 20 edits 3 s apart, default delay: rebuild p50 1,020 ms, against 644–797 ms with
off. - CPU time is 59 s, against 35–38 s. A 3 s delay gives 37–44 s.
MIMALLOC_ALLOW_THP=0removes the difference.
Could the Known gaps section mention this case and suggest a longer delay or off?
## [1.3.4] - 2026-11-26 ### 🚀 Features - add builtin `injectPlugin` with `include`/`exclude` (#11290) by @onmax - magic-string: support explicit sourcemap locations (#11884) by @IWANABETHATGUY - introduce `declaredModuleSize` to allow plugins to declare a module's real size (#11844) by @hyfdev - binding: add dropInner() to 12 binding classes and extract release_arc helper (#11855) by @Brooooooklyn - inline-common-chunks: add `maxDuplicatedSize` to keep widely copied chunks as files (#11845) by @mattlewis92 - cli: report when a watch round finishes (#11820) by @hyfdev - rolldown_plugin_vite_build_import_analysis: avoid stripping import attributes when `experimental.importAttributes` is enabled (#11802) by @sapphi-red - import-attributes: warn when a non-ESM output drops the import attributes of an external (#11797) by @shulaoda - warn when the `watch` option is passed to `build()` (#11781) by @shulaoda ### 🐛 Bug Fixes - keep_names: restore hoisted function names before the chunk's modules run (#11962) by @hyfdev - external: don't drop `_/` from relative external imports (#11968) by @hyfdev - external: don't panic on empty output filename with relative externals (#11963) by @hyfdev - use the same path as direct imports for externals re-exported with `export *` (#11964) by @hyfdev - sourcemap: don't panic on empty output filename (#11966) by @hyfdev - sourcemap: treat empty `sourcemapFileNames` as unset (#11967) by @hyfdev - rename clashing names in execution order with `chunkModulesOrder: 'module-id'` (#11943) by @hyfdev - code-splitting: stop counting JSON modules as 0 bytes (#11939) by @hyfdev - fetch changed modules from their creating resolution in incremental rebuilds (#11837) by @h-a-n-a - code-splitting: keep import order through entry re-exports (#11906) by @hyfdev - cjs: keep CommonJS named exports in `export *` of a dynamically imported module (#11835) by @hyfdev - plugin: remove internal keys from plugin and code splitting group contexts (#11914) by @hyfdev - remove the leftover `watch.notify` from the option validator (#11918) by @shulaoda - return the group chunk file from `getFileName()` for a merged emitted entry (#11858) by @IWANABETHATGUY - dev: let `this.load` of an unchanged module finish during a rebuild (#11911) by @hyfdev - code-splitting: avoid an extra shared chunk when an entry only re-exports another entry (#11847) by @hyfdev - treeshake: remove unused objects containing identity function calls (#11852) by @hyfdev - cjs: avoid `ReferenceError` when re-exporting from an external `export *` in another chunk (#11848) by @hyfdev - binding: remove stale WASI workaround in to_binding_error (#11890) by @Brooooooklyn - inline-const: respect `inlineConst` options for default exports (#11851) by @hyfdev - magic-string: keep trailing lines in decoded maps (#11882) by @IWANABETHATGUY - magic-string: preserve column mappings through trim (#11881) by @IWANABETHATGUY - magic-string: map each line of multiline replacements (#11880) by @IWANABETHATGUY - follow Rollup for module meta and moduleSideEffects set by plugins (#11792) by @h-a-n-a - code-splitting: import the bindings a CommonJS entry re-exports from an ES module (#11839) by @hyfdev - cjs: stop overwriting `module.exports` of a CommonJS entry that re-exports an ES module (#11846) by @hyfdev - sourcemap: accept undefined source entries from plugins (#11850) by @fengmk2 - code-splitting: unblock top-level awaited dynamic imports in manual groups (#11819) by @hyfdev - runtime: resolve `require()` from the calling chunk in Node ESM output (#11834) by @hyfdev - plugin: throw instead of panicking when a saved transform context calls `getCombinedSourcemap` (#11838) by @hyfdev - code-splitting: only code-less entries keep side-effect-free static import edges (#11199) by @mattlewis92 - make `getCombinedSourcemap` work with `experimental.nativeMagicString` (#11107) by @IWANABETHATGUY - plugin: avoid hangs when resolveId awaits this.load() (#11824) by @shulaoda - keep template chunk names from overwriting explicit file names (#11831) by @hyfdev - code-splitting: skip redundant re-export chunks (#11817) by @hyfdev - preserve build errors when `buildEnd` fails (#11828) by @sapphi-red - preserve top-level using with topLevelVar (#11804) by @akshathayadav378-boop - treeshake: keep array destructuring that calls an unknown iterator (#11812) by @IWANABETHATGUY - preserve `export` names starting with `*` in ModuleInfo.exports (#11825) by @sapphi-red - treeshake: keep calls to functions that direct `eval` can replace (#11811) by @IWANABETHATGUY - keep each source's content in a multi-source transform sourcemap (#11246) by @IWANABETHATGUY - treeshake: keep calls to empty functions with a rest parameter default (#11810) by @IWANABETHATGUY - plugin: allow this.load() while resolving entries (#11816) by @hyfdev - cli: avoid a WASI hang when watch mode exits normally (#11815) by @shulaoda - report effective moduleSideEffects in getModuleInfo and this.resolve (#11422) by @cestercian - code-splitting: avoid an import cycle through an entry's re-exports (#11803) by @hyfdev - treeshake: apply @__NO_SIDE_EFFECTS__ to functions exported after declaration (#11222) by @araishi - code-splitting: keep unused entry re-exports from loading lazy chunks (#11753) by @hyfdev - code-splitting: keep re-exported bindings out of dynamic import namespaces (#11799) by @hyfdev - perf-kit: Node mode times out under the inspector with `--ready exit` or an anchored `stdout:` pattern (#11416) by @IWANABETHATGUY - treeshaking: drop dead dynamic imports that form a cycle (#11768) by @hyfdev - binding: release the WASI runtime when a callable builtin plugin hook rejects (#11786) by @shulaoda - perf-kit: print real imports in the why chain (#11500) by @IWANABETHATGUY - chunk: name emitted chunks before shared chunks (#11790) by @hyfdev - cjs: forward exports from duplicate CommonJS entries (#11756) by @hyfdev - code-splitting: keep chained emitted entries from becoming empty facades (#11090) by @Huzaifa-Asif ### 💼 Other - wasi: bundle self-contained WASI loaders, staging script, and reactor checks (#11843) by @Brooooooklyn ### 🚜 Refactor - scan: remove an unreachable branch when collecting dynamic import entries (#11919) by @shulaoda - cli: replace the unreachable prototype pollution guard with a test (#11925) by @shulaoda - remove the unused `DeterminedSideEffects::to_module_side_effects` (#11926) by @shulaoda - remove more unused types, functions and re-exports (#11922) by @shulaoda - link_stage: handle required modules only in the pre-pass (#11920) by @shulaoda - cli: remove the leftover `inject` from the CLI options type (#11924) by @shulaoda - rolldown_plugin_vite_build_import_analysis: remove the unused `optimizeModulePreloadRelativePaths` option (#11923) by @shulaoda - remove experimental `freeExternalMemory` (#11886) by @shulaoda - rust: drop direct tokio dependencies from core library crates (#11841) by @Brooooooklyn - rolldown_plugin: move `normalize_transform_sourcemap` to utils (#11247) by @IWANABETHATGUY - remove the unused `plugins_are_slow` method (#11800) by @shulaoda - remove parallel plugin support (#11789) by @h-a-n-a - remove the unused `is_css` sourcemap flag (#11782) by @shulaoda ### 📚 Documentation - rename javascript to JavaScript (#11958) by @mdong1909 - say that resolveId fails the build when the same id is external and not external (#11910) by @h-a-n-a - explain which resolution sets meta and moduleSideEffects in resolveId (#11907) by @h-a-n-a - resolve the import in the `moduleSideEffects` plugin example (#11860) by @hyfdev - clarify side-effect-free module behavior (#11856) by @IWANABETHATGUY - clarify the behavior when `buildEnd` / `renderError` itself errors (#11829) by @sapphi-red - add docs for `code` / `plugin` / `pluginCode` of `RolldownLog` (#11827) by @sapphi-red - explain that a module in an entry chunk runs after the common chunks it imports (#11822) by @hyfdev - magic-string: document `generateDecodedMap` and the segments of `hires: false` maps (#11791) by @IWANABETHATGUY ### ⚡ Performance - binding: return memory to the OS once rolldown is idle (#11655) by @shulaoda - scan: reserve symbol capacity for each module's facade symbols (#11854) by @magurotuna - runtime: stop using bound functions as `__copyProps` getters (#11826) by @magurotuna - replace `IndexVec<ModuleIdx, bool>` with `IndexBitSet` (#11805) by @IWANABETHATGUY - rolldown_plugin_vite_manifest: look up chunk names by file name once per build (#11697) by @Boshen - drop module sourcemaps after the chunk is joined (#11773) by @shulaoda ### 🧪 Testing - magic-string: re-enable two passing compatibility tests (#11879) by @IWANABETHATGUY - node: add standalone runtime/proxy/retained-context tests and vitest binding staging (#11842) by @Brooooooklyn - cli: stop watch CLI tests from hanging on Windows (#11821) by @shulaoda ### ⚙️ Miscellaneous Tasks - delete cancelled pkg.pr.new runs on main and debounce for 15 mins (#11928) by @shulaoda - remove the unused `serde` features of rolldown, rolldown_plugin and rolldown_common (#11927) by @shulaoda - deps: update vite-plus to v1.8.0 in the workspace and CI (#11896) by @camc314 - deps: update rollup submodule for tests to v4.68.8 (#11901) by @rolldown-guard[bot] - deps: update test262 submodule for tests (#11902) by @rolldown-guard[bot] - remove the graphite merge-when-ready label check (#11904) by @shulaoda - deps: pin walkdir to 2.5.0 (#11897) by @hyfdev - deps: remove remove-unused-vars (#11895) by @camc314 - deps: update rust crate testing_macros to v3 (#11876) by @renovate[bot] - deps: update rust crates (#11873) by @renovate[bot] - deps: update npm packages (#11872) by @renovate[bot] - deps: upgrade oxc to 0.160.0 (#11885) by @camc314 - deps: update github actions (#11874) by @renovate[bot] - rust: standalone runtime prep (devtools sync writer, TestDir, 1ms debounce, Wasm sourcemap inline, parking_lot_core patch) (#11840) by @Brooooooklyn - run setup steps one by one on Windows (#11849) by @shulaoda ###◀️ Revert - "feat(binding): add dropInner() to 12 binding classes and extract release_arc helper (#11855)" (#11898) by @shulaoda - "fix(code-splitting): keep chained emitted entries from becoming empty facades (#11090)" (#11891) by @hyfdev ### ❤️ New Contributors * @fengmk2 made their first contribution in [#11850](#11850) * @akshathayadav378-boop made their first contribution in [#11804](#11804) * @araishi made their first contribution in [#11222](#11222) * @Huzaifa-Asif made their first contribution in [#11090](#11090) Co-authored-by: shulaoda <[email protected]>
Closes #11143
Closes #9330
Related to #10985, #11189 and #11233
After a build, rolldown keeps most of the memory it used, even when the output is no longer used. Freed memory stays with idle worker threads and does not go back to the OS. V8 also does not know how much native memory an output holds, so it can take a long time to collect a dropped output.
What this PR does
alwaysormadvise), memory goes back to the OS in 64 KiB pieces instead of 2 MiB ones. On Windows, memory is committed only when it is used. AMIMALLOC_*environment variable still overrides both.ROLLDOWN_MEMORY_RECLAIM_DELAY=<ms>changes the 500 ms, andoffturns off the cleanup and both allocator settings.mimalloc-safe0.1.71).The design and the rejected alternatives are in
internal-docs/memory-reclaim/.Results
main is e641a93. PR is ce99614, this branch with that main merged in. All are local release builds. PR has mimalloc 3.7.0 and main has 3.6.1, so the numbers below include the update. Each number is the median of 3 runs.
phys_footprint(the "Memory" column of Activity Monitor).madvise, memory isRssAnon, and peak isVmHWM.Memory after the work stops (MB)
On Windows, the "before the 10th build" row is the full working set, because reading the private working set is slow and would lengthen the pause.
In Vite cold dev, most of what stays is the JS heap. On macOS, the memory that mimalloc holds is rolldown's own. By the time the page closes, it goes from 887 to 236 MB for lobehub, and from 1215 to 23 MB for the #9330 repro. The JS heap keeps shrinking for minutes after the page closes, on main too, so the lobehub row waits 270 s.
Peak memory is lower or within noise in every case. When builds repeat, it is 42 to 53% lower on all three systems, with a build every 0 to 3 s and with #10985 in a loop.
Peak memory of one build (MB)
The macOS lobehub sourcemap peak and the Windows lobehub and vinext peaks are within noise. On macOS, the PR's lobehub sourcemap peak moves by about 800 MB from run to run. The Windows commit is the highest "Commit size" in Task Manager. It drops more than the peak, because memory is committed only when it is used. The lower Linux peaks come from mimalloc 3.7, which keeps much less memory resident with transparent huge pages. They stay the same with
ROLLDOWN_MEMORY_RECLAIM_DELAY=off, which turns off the cleanup and both allocator settings. WithMIMALLOC_ALLOW_THP=0, the PR is only 2 to 3% lower than main, as on macOS.Peak memory in Vite dev (MB)
These are the same runs as in the first table. Cold dev starts with an empty deps cache.
Time of one build
No time here is clearly slower. lobehub on macOS and Linux is about 1% faster, and the rest are within noise.
Known gaps
vite --experimentalBundle) memory grows with every rebuild until a full GC #11189 bundled dev, it is 14% higher on macOS, 17% on Linux and 4% on Windows. With a build every 1 to 3 s, it is about 6% higher on macOS, and up to 7% on Linux and 12% on Windows. Other Linux and Windows cases show no clear rise, except one three.js x10 build on Linux (3%). WithROLLDOWN_MEMORY_RECLAIM_DELAY=off, CPU time on macOS is the same as main's.transform,minifyandparsefromrolldown/utilsdo not start the cleanup. Their async versions run on Node's libuv thread pool, which the cleanup does not reach. Their sync versions run on the calling JS thread, which the cleanup reaches only if that thread has created a bundler, a watcher or a dev engine.MADV_HUGEPAGE, so with transparent huge pages and the defaultdefrag=madvise, the kernel compacts memory synchronously when the next build touches the returned pages, and most of these compactions fail. On such a machine (x86_64, kernel 6.18, THPalways, 7 days of uptime), an API build after a 2 s pause took 675–741 ms against 606–611 ms withoff, and watch mode with an edit every 3 s used 59 s of CPU against 35–38 s.ROLLDOWN_MEMORY_RECLAIM_DELAY=3000brought the CPU back to 37–44 s, andofforMIMALLOC_ALLOW_THP=0removes the difference.MIMALLOC_ALLOW_THP=0avoids it, but makes builds 4 to 8% slower.mi_theap_quiescent_abandonis new in mimalloc 3.6 and is in the experimental part of its API.