Skip to content
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

garbage collect the AST while outputting code #1189

Merged
merged 2 commits into from
May 1, 2022

Conversation

fabiosantoscode
Copy link
Collaborator

@fabiosantoscode fabiosantoscode commented Apr 30, 2022

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

During production builds, [source maps] are disabled as generating source maps can significantly increase build times and memory usage

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.

@@ -2278,7 +2269,6 @@ var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExp
this.extends = props.extends;
this.properties = props.properties;
this.variables = props.variables;
this.functions = props.functions;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property isn't used anymore, as it was all merged into .variables

node.block_scope.enclosed = undefined;
node.parent_scope = undefined;
}
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done before the options.sourceMap.includeSources check below, which increases memory usage.

@fabiosantoscode fabiosantoscode merged commit 878a631 into master May 1, 2022
@fabiosantoscode fabiosantoscode deleted the gc-ast-for-ram-savings branch May 1, 2022 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants