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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve AST garbage collection #4762
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4762 +/- ##
=======================================
Coverage 99.03% 99.03%
=======================================
Files 217 217
Lines 7762 7772 +10
Branches 2148 2153 +5
=======================================
+ Hits 7687 7697 +10
Misses 24 24
Partials 51 51
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Added a test and found a bug (fixed). I hope this fixes the coverage. I seem to get tests errors when running |
@bluwy what method did you use to determine peak memory in your tests? I used rollup@2.79.1 -- 2.11gb |
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.
Very nice, this is really top-notch work. Will leave it open for at least a day so that people can do their benchmarking, but it looks very reasonable to me.
@chriscasola Mine was rather unscientific by observing activity monitor 馃槃 Running your command I'm getting similar results too, but I think what's happening is that node will still use and allocate the same amount of memory (which what As your example only took 2gb, node doesn't need to free up memory so it shows the same number. I'll update the PR title to better reflect this. |
This PR has been released as part of rollup@3.8.1. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
vitejs/vite#2433
Description
This PR does 2 things:
esTreeNode
toBaseNode
(except dynamic import case). This means that AST leaf nodes are only copied in theparseNode
phase, which also prevents the leaf node being duplicated in bothesTreeNode
andBaseNode
itself.esTreeNode
can then be garbage collected once it leaves the constructor call.ModuleInfo.ast
lazy and apply LRU cache. Now Rollup doesn't need to keep the AST in memory unless requested. A fixed size LRU cache is added only for perf if someone accesses it repeatedly. This is non-configurable (for now) since it's hard to find the right number. In practice, many plugins don't readModuleInfo.ast
.Caching
If caching is enabled, we keep the old method as it's more efficient to share the AST when building the final cache object. If it's disabled, we use the new lazy method. This also means that this optimization is opt-in only by setting
cache: false
.Numbers
For https://github.com/withastro/docs/tree/chris/mdx, I saw peak memory usage from 4.5GB to 3.5GB.
For https://github.com/Axeldeblen/realworld-big-build-vite-4, it failed with a OOM error, but this PR made it work with peak memory of 3.5GB.
(Note: It's more accurate to say that this PR allows more memory to be freed when the process nears the max heap limit, allowing users to run larger builds)
Misc
Thanks Astro for sponsoring the work 馃檪