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

Reduce memory usage by releasing webpack stats objects after compile #858

Merged
merged 1 commit into from Jun 8, 2021

Conversation

janicduplessis
Copy link
Contributor

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:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@janicduplessis
Copy link
Contributor Author

Accomplish something similar to #570, but simpler.

Should fix #299

@j0k3r j0k3r added this to the 5.5.1 milestone Jun 7, 2021
@j0k3r
Copy link
Member

j0k3r commented Jun 7, 2021

This looks interesting, I'll try out on some project and let you know!
In the mean time, could you rebase against the master? Thanks 🙏

@j0k3r j0k3r self-requested a review June 7, 2021 11:04
@janicduplessis
Copy link
Contributor Author

Rebased!

Copy link
Member

@j0k3r j0k3r left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

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.

JavaScript heap out of memory when packaging many functions
2 participants