question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] Persistent build cache by default

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:92
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

40reactions
SanderEliascommented, Aug 11, 2021

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 cache
  • ng cache statistics Gives the size, location and so
  • ng cache folder shows the folder it is using
  • ng cache folder /some/folder sets the folder used for caching
  • ng cache off turns off caching
  • ng cache on turns on caching

By adding those as commands to the CLI it becomes much easier to control for people not versed in DevOps.

12reactions
e-ozcommented, Aug 11, 2021

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular on Twitter: "Persistent build cache is now enabled by ...
Persistent build cache is now enabled by default! In August, we ran an RFC on an experimental feature to persist build information to...
Read more >
HTTP Caching RFC 9111 - IETF Datatracker
Although caching is an entirely OPTIONAL feature of HTTP, it can be assumed that reusing a cached response is desirable and that such...
Read more >
Build Cache - Gradle User Manual
The Gradle build cache is a cache mechanism that aims to save time by reusing outputs produced by other builds. The build cache...
Read more >
Angular v13 is now Available
The valuable feedback from [RFC] Persistent build cache by default led to this tooling update that results in up to 68% improvement in...
Read more >
RFC: Add an LLVM CAS library and experiment with fine ...
Persistent caching across contexts is often easy when inputs and outputs are stored in a CAS. The action cache can be a key-value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found