[package.json] Enable max_old_space_size Override for Desktop #38576
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.
The behavior of heap limits and garbage collection in Node 12 has changed such that attempts to build wp-desktop with updated Calypso (which is now using Node 12) fail due to memory pressure. As-is, Node will attempt to use up to the set heap allocation (
max_old_space_size
) of 8GB but runs into the hard 4GB limit of Circle CI's RAM at which point Node kills the build process.We need to tell Node to allocate to the heap less than the Docker container's 4GB RAM limit. However, it seems there's a fundamental flaw in the way
NODE_ARGS
is set such that this parameter cannot be overriden at build time.Simplified Example
A simple example to illustrate:
In a nutshell, the above example illustrates the problem with the way
NODE_ARGS
is currently set. We need to be able to override this value when building wp-desktop, but are unable to.(Side note: For some reason, this hasn't been an issue until Node 12 updated the way memory is managed. In addition, this only seems to affect Calypso as it is built for wp-desktop. However the issue with the way
NODE_ARGS
is set is a problem regardless.)Changes proposed in this Pull Request
The values of
NODE_ARGS
andmax_old_space_size
for wp-desktop should be able to be overriden per the constraints of the hardware Caypso is being built on. Using the syntaxNODE_ARGS=${NODE_ARGS:---max_old_space_size=8192}
ensures that the default value of 8192MB will be used unless overridden by the caller, so we can maintain the existing behavior and customize this parameter where necessary.Testing instructions
By pointing wp-desktop at this branch, we can verify that enabling the override of the hard-coded
max_old_space_size
value fixes the build failure on CI for wp-desktop.max_old_space_size
override is respected, and Calypso build is successful (build job)