[RFC] Persistent build cache by default
See original GitHub issueAuthor: Alan Agius (@alan-agius4) Status: Open Closing Date: 2021-08-24
Summary
In Angular CLI version 12.1, we introduced an experimental opt-in feature to persist build information to disk. This under the hood uses Webpack’s persistent cache feature.
Users can opt-in to the experimental build persistent cache using the NG_PERSISTENT_BUILD_CACHE=1
environment variable.
NG_PERSISTENT_BUILD_CACHE=1 ng <serve|test|build|...>
When opting to use this feature, information of the current build is persisted on disk, and reused in the subsequent reinitialization of the build pipeline via ng build
, ng serve
and other ng
commands. The improvement in cold build times we’ve seen in the real applications is up to 68%. This does come at the cost of an increase in memory usage.
Proposal
We are proposing that in version 13, we enable persistent build cache by default, whilst still providing an option to opt-out. We also intend to introduce a new command ng cache
which would facilitate enabling, disabling and purging the cache.
The persistent build cache typically speeds up local development workflows, because these workflows often depend on performing full, non-incremental builds.
However we found the impact negatively in CI environments because of the increase in memory usage and the cache which is located in node_modules/.cache/angular
is typically not stored after each build and restored before each one. For this reason we propose that persistent build cache is disabled when the build is running in a CI environment. We can determine this by checking for the presence of the CI environment variable.
Community feedback
We’d like the community to weigh in and provide feedback on a number of points.
-
How
NG_PERSISTENT_BUILD_CACHE
affects the development when building, serving and testing an application. -
If any, what is the observed memory increase.
Non Windows users can run the below to gather this data:
rm -rf node_modules/.cache
/usr/bin/time NG_PERSISTENT_BUILD_CACHE=0 ng <serve|test|build|...>
rm -rf node_modules/.cache
/usr/bin/time NG_PERSISTENT_BUILD_CACHE=1 ng <serve|test|build|...>
- Should it be possible to provide an alternate cache path, where possibly it could be leveraged on CI, to restore the cache directory before each run.
node_modues/.cache
is currently used as cache location.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:92
- Comments:12 (2 by maintainers)
Top GitHub Comments
I love to see this turned on by default. Yes, I would like to be able to move the folder to a different place, as that can make it easier to store than in CI/CD settings. Also, I would love to have those settings to be easily managed by the CLI itself. So, here is my wishlist in no particular order:
ng cache clear
Clear out the cacheng cache statistics
Gives the size, location and song cache folder
shows the folder it is usingng cache folder /some/folder
sets the folder used for cachingng cache off
turns off cachingng cache on
turns on cachingBy adding those as commands to the CLI it becomes much easier to control for people not versed in DevOps.
I vote for making it turned on by default but with the setting in angular.json to turn it off (similar to “buildOptimization: true”). This way, “production” and “ci” configurations could turn it off if needed, while dev builds will run significantly faster (and it’s where it matters the most).