garbage collect the AST while outputting code #1189
Merged
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.
Currently, while the code is being printed, the whole AST is in memory.
The AST is really heavy, and people rightfully complain about memory usage (#164, #283)
The NextJS documentation even mentions the issue being exacerbated by source maps, though I'm not sure it's just about Terser
To avoid using more RAM, delete the AST as we go through it.
The new internal format option
_destroy_ast
deletes chunks of the AST during the output phase, and it's automatically set by minify.js.The chunks being deleted are functions, as they can get pretty large. I'm pretty sure this doesn't delete everything that should be deleted, but memory reported actually goes down while outputting.