-
Notifications
You must be signed in to change notification settings - Fork 682
fix(rolldown_binding): use Weak<OutputChunk> to prevent memory leak
#6346
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
fix(rolldown_binding): use Weak<OutputChunk> to prevent memory leak
#6346
Conversation
The js side should not own the Arc.
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. |
✅ Deploy Preview for rolldown-rs canceled.
|
| } | ||
|
|
||
| fn inner(&self) -> Arc<OutputAsset> { | ||
| self.inner.upgrade().unwrap() |
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.
Instead of crashing, the js side can set the value to undefined, or we throw a panic message "Rolldown has been shutdown, access to this data is no longer possible".
| pub(crate) cache: ScanStageCache, | ||
| pub(crate) session: rolldown_debug::Session, | ||
| pub(crate) build_count: u32, | ||
| pub(crate) assets: Vec<Output>, |
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.
Bundler needs to own the Arcs from Output.
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.
Not oppose this direction, but would it casue error if the bundler/assets get dropped and user try to access the assets?
This brings up a convention that if users wants to access the asset, they shouldn't make the the js object Bundler get GCed, which is hard thing to tell in the js world due to js doesn't have ownership concept.
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.
Yes, for script usages, use after free will not be allowed. i.e. it will crash when accessing asset data after rolldown has been closed.
|
|
||
| self.assets.clear(); | ||
| self.cache = ScanStageCache::default(); | ||
| self.file_emitter.clear(); |
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.
We need to clear everything stored in Bundler instead of relying on Drop.
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.
I think this improvement could be appied first. No negative point found.
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.
Had applied this one in #6483.
| } | ||
|
|
||
| let mut output = bundle_output?; | ||
| self.assets.extend(output.assets.iter().map(Clone::clone)); |
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.
This line might get triggered many times due to incremental build.
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.
Something else should own the assets, I stored them in bundler to prove my hypothesis.
…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 ```
may fix #6121
The js side should not own the Arc.