-
Notifications
You must be signed in to change notification settings - Fork 682
feat(node): automatically clean up external memory when calling close
#6707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label graphite: merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
f590d80 to
a0f6758
Compare
|
CI fails due to the same reason as #6694 (comment) and #6718. |
closeclose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements automatic cleanup of external memory when calling close() on a Rolldown build. Objects implementing ExternalMemoryHandle are now tracked using WeakRef and cleaned up when the build is closed, with an option to keep data alive in the Node.js heap.
Key changes:
- Added
WeakRef-based tracking of external memory handles inRolldownBuild - Introduced legacy decorators (
@lazyand@nonEnumerable) to manage lazy field evaluation and property visibility - Refactored output object creation to use class-based implementations (
OutputChunkImpl,OutputAssetImpl) instead of proxy-based approach
Reviewed Changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
pnpm-workspace.yaml |
Updated tsx version from ^4.19.4 to ^4.20.6 and moved its position in catalog |
packages/rolldown/tsconfig.json |
Enabled experimentalDecorators compiler option to support legacy decorators |
packages/rolldown/tests/fixtures/topics/rollup-compat/object-properties/main.js |
Added test fixture with simple export statement |
packages/rolldown/tests/fixtures/topics/rollup-compat/object-properties/_config.ts |
Added comprehensive test validating non-enumerable __rolldown_external_memory_handle__ method |
packages/rolldown/tests/fixtures/topics/free-external-memory/main.ts |
Added test demonstrating freeExternalMemory API usage |
packages/rolldown/tests/fixtures/topics/free-external-memory/_config.ts |
Added runtime tests for freeExternalMemory function |
packages/rolldown/src/utils/transform-to-rollup-output.ts |
Refactored to use OutputChunkImpl and OutputAssetImpl classes instead of inline object creation |
packages/rolldown/src/types/rolldown-output.ts |
Extended RolldownOutput interface to implement ExternalMemoryHandle |
packages/rolldown/src/types/rolldown-output-impl.ts |
Updated to use @lazy and @nonEnumerable decorators and cascade cleanup to output items |
packages/rolldown/src/types/output-chunk-impl.ts |
New class implementing OutputChunk with lazy-evaluated properties and cleanup logic |
packages/rolldown/src/types/output-asset-impl.ts |
New class implementing OutputAsset with lazy-evaluated properties and cleanup logic |
packages/rolldown/src/types/external-memory-handle.ts |
Updated signature to accept optional keepDataAlive parameter and enhanced documentation |
packages/rolldown/src/experimental-index.ts |
Exported freeExternalMemory function for experimental API |
packages/rolldown/src/decorators/non-enumerable.ts |
New decorator making properties non-enumerable |
packages/rolldown/src/decorators/lazy.ts |
New decorator for lazy-evaluated, cached getters with auto-registration |
packages/rolldown/src/api/rolldown/rolldown-build.ts |
Added WeakRef tracking and cleanup logic in close() method with keepDataAlive option |
packages/rolldown/package.json |
Changed build script from tsx to oxnode and reordered dependencies |
packages/rolldown/build.ts |
Configured legacy decorator support in transform options |
packages/pluginutils/tsconfig.json |
Enabled experimentalDecorators with explanatory comment about oxnode limitation |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a0f6758 to
1a2ffa3
Compare
This comment was marked as resolved.
This comment was marked as resolved.
47e39f7 to
1f2999e
Compare
45f0dcb to
2fd54fc
Compare
|
Is it possible to add a test that ensures the memory is actually released? |
The test could ensure the |
|
I think we should test how much perf impact this change has. |
2fd54fc to
014c762
Compare
1f2999e to
2c52aa5
Compare
…icting binary (#6708) Solves CI problems that #6707 and #6694 encountered. Refs: - #6694 (comment)
|
A significant performace impact on calling |
…emory immediately (#6721) This PR consolidates #6707 and #6696. Part of #6346. ```typescript import { freeExternalMemory } from 'rolldown/experimental'; const bundle = await build.generate(); freeExternalMemory(bundle) bundle.output // error ``` ```typescript import { freeExternalMemory } from 'rolldown/experimental'; const bundle = await build.generate(); freeExternalMemory(bundle, /*keepDataAlive:*/ true) bundle.output // no error ```

Weak<OutputChunk>to prevent memory leak #6346Explanation:
close, Objects that impmentsExternalMemoryHandlewould be cleaned up automatically fromRolldownBuild#externalMemoryHandles.WeakRefto store objects, so it won't be an issue to that rolldown itself prevents objects from being GCed by nodejsWeakRef