Reduce memory usage by releasing webpack stats objects after compile #858
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.
What did you implement:
The current implementation keeps the full webpack stats object for all functions. This object is huge and causes very large memory usage when using package: individually and a large number of functions.
The webpack stats object is used for 2 things, outputPath and external modules. Instead of keeping the full stats object around, we calculate the outputPath and external modules after compilation and discard the stats object. Then packageModules and packageExternalModules can use these values directly instead of the stats object.
How did you implement it:
Set outputPath and externalModules in the compile phase and discard webpack stats object.
How can we verify it:
Tested this change in a large serverless app.
Before: Memory usage slowly increases up to 7.2gb, builds in ~1500s
After: Memory usage hovers around 1.5gb, builds in ~1000s
Todos:
Is this ready for review?: YES
Is it a breaking change?: NO