Repository navigation
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-plugin-context-build-lifetime-rolldown-rs.voidzero-docs.workers.dev (commit 62670b1)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
shulaoda
force-pushed
the
fix/plugin-context-build-lifetime
branch
from
November 24, 2026 01:05
0fb4ea4 to
2f7ae9b
Compare
shulaoda
force-pushed
the
revert/binding-drop-inner
branch
from
November 24, 2026 01:05
7bdc1b5 to
9d289ee
Compare
shulaoda
added a commit
that referenced
this pull request
Nov 24, 2026
…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.
shulaoda
force-pushed
the
fix/plugin-context-build-lifetime
branch
from
November 24, 2026 01:11
2f7ae9b to
62670b1
Compare
This branch has not been deployed
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.
Stacked on #11898, which reverts #11855.
Related to #10268
The GC of the JS engine frees the native data behind a binding object only when it collects the object. On wasm it does not see Wasm memory, so it can wait very long, and the data of every build piles up. #11855 and #10268 work around this by calling
dropInner()from JS after each hook, on threadless WASI only.This PR follows one rule instead. The GC that frees a piece of memory must be able to see it, or must not be needed at all.
What changes
BindingPluginContextholds the plugin context weakly, and the plugin driver owns it until the build finishes. A context forked for oneresolveIdcall points to the driver's context and keeps the skipped calls itself.BindingTransformPluginContextholds the transform context weakly, and the driver keeps each transform context until the module's sourcemap chain changes. After the build, a kept context throwsThis plugin context can no longer be used because its build has finished.parse,metaand the log methods keep working.renderChunkmeta and module info. The data lives in the JS heap, where the GC sees it, so nothing needs to be dropped. Each of these isEither<BindingX, BindingXData>in the binding, so the generated types are the same on every target. Native keeps the lazy objects.No
dropInner()is needed for any of these classes.Behavior of a kept context
Rollup 4.68.7, main, #10268 on threadless WASI and this PR, all run with the same script.
getCombinedSourcemapwhile the module's chain is unchangedresolveId, used later in the same buildgenerate(), used in the secondresolvethrows, the rest read the first buildemitFile,loadorresolveafterclose()resolvethrowsgetModuleInfo,getModuleIdsorgetFileNameafterclose()parse,metaorwarnafterclose()The only case where this PR differs from Rollup with a useful result is reading build data after
close(). Keeping that data would mean keeping it until GC again.Memory
All numbers use the 300-module graph of the workerd suite of #10268.
Wasm in Node (
wasm32-wasip1-threads), live Rust heap after each of 100 builds, average and maximum in MiB. The Wasm heap was counted with an allocator wrapper that is not part of this PR.hooksaddsmoduleParsed,renderChunkreadingchunk.modulesandgenerateBundlereading the code.nohookshooksgc()after each buildNode still runs its GC now and then, so the weak contexts alone change little here. In workerd the GC does not collect these objects, and the contexts matter much more. This is the workerd suite of #10268 (threadless WASI, one reused instance, 20 rebuilds), as Wasm memory growth per rebuild in MiB.
nohookstransform-astdropInner()on the three context classesOn native, the live Rust heap over 100 builds without
gc()goes from 3.1 to 29.1 MiB on main and from 0.8 to 26.8 MiB with weak contexts. The build already clears most of its data when it finishes. The rest is outputs, which native keeps lazy and #11655 reports to V8.Cost
A wasm build copies every field when the data crosses to JS, also the fields that JS never reads. For the
hookscase above that is 108.7 to 112.2 ms per build on main and 114.9 to 116.0 ms with this PR, about 4 ms. AgenerateBundleorwriteBundlehook gets its own copy of the bundle, so each such hook adds a copy. Native does not change.Not covered
BindingNormalizedOptionsandBindingChunkingContextstay native objects. Both are small and shared by the whole build, and the options objects that hooks get already hold plain values.