Skip to content

[RFC] Persistent build cache by default #21545

Closed
@alan-agius4

Description

@alan-agius4

Author: 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions