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

Angular cache dir (.angular) grows and grows #22323

Closed
jcompagner opened this issue Dec 9, 2021 · 12 comments · Fixed by #22473
Closed

Angular cache dir (.angular) grows and grows #22323

jcompagner opened this issue Dec 9, 2021 · 12 comments · Fixed by #22473

Comments

@jcompagner
Copy link

When building our product with Angular 13 the .angular/cache is now generated.
At a first build thats around 500MB but it will not take long and it is grown to 9GB is that normal?

What is exactly cached there and how is it reused?

@alan-agius4
Copy link
Collaborator

Hi @jcompagner,

There are several parts of the pipeline that are cached on disk, the main benefit of this is that future compilations become warm as the build state is restored from disk instead of having to start the build from a cold state. This helps to decrease the build time by up to 65% as a number of computations are not performed.

There are a number of things that are cached, including but not limited to:

  • Babel transformations
  • Results of the minified CSS and JS
  • Build dependencies and resolutions
  • Modules transformation result

The cache is expected to continue to grow, unless it is periodically purged by the users. The more code changes are performed in a repo, the larger the cache will become. You can read the cache documentation on how to the clear the cache.

In future, we are hoping to perform automatic cleanups of stalled cache data.

It would be interesting to know which files/directories are consuming the most disk usage. Can you please provide some metrics?

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Dec 9, 2021
@jcompagner
Copy link
Author

currently after a clean with a first build:

.angular\cache\angular-webpack\452f48df2f16eff7f35d217be73a1e17c8ec5851

the 0.pack file is taking almost all the space 447MB (the whole cache dir id 472MB)

after i have installed 2 updates of packages and run a build the total size si already grown to 516MB
and now the 0.pack file shrink to 207MB but i have a 1.pack now also that is 266MB and a 2.pack file that is 9MB


-a--- 9-12-2021 17:22 217749179 0.pack
-a--- 9-12-2021 17:22 279087529 1.pack
-a--- 9-12-2021 17:22 9778010 2.pack
-a--- 9-12-2021 17:22 7874557 index.pack
-a--- 9-12-2021 12:50 7649466 index.pack.old

then i run one build again:

-a--- 9-12-2021 17:22 217749179 0.pack
-a--- 9-12-2021 17:28 278296822 1.pack
-a--- 9-12-2021 17:22 9778010 2.pack
-a--- 9-12-2021 17:28 4769610 3.pack
-a--- 9-12-2021 17:28 7874590 index.pack
-a--- 9-12-2021 17:22 7874557 index.pack.old

running one other build again:


-a--- 9-12-2021 17:22 217749179 0.pack
-a--- 9-12-2021 17:28 278296822 1.pack
-a--- 9-12-2021 17:22 9778010 2.pack
-a--- 9-12-2021 17:29 149 3.pack
-a--- 9-12-2021 17:29 4769605 4.pack
-a--- 9-12-2021 17:29 7874619 index.pack
-a--- 9-12-2021 17:28 7874590 index.pack.old

(these builds are not production builds but kind of debug builds without watch)

so every build it generates a bit more and maybe it adjust the last file it added...

@alan-agius4
Copy link
Collaborator

Webpack have actually a PR in flight to delete old pack files webpack/webpack#14661.

@jcompagner
Copy link
Author

by the way would it be possible to not include the fully path in those pack files?
that would i think greatly reduce the size for me. my full path is:

D:\servoy_inst\202112\developer\ws.metadata.plugins\com.servoy.eclipse.ngclient.ui\target\

if i count that now over the latest pack files described above its about 140K hits...
thats maybe around 13MB ?

@alan-agius4
Copy link
Collaborator

The pack file are generated by Webpack and we don't have control over their contents.

@jcompagner
Copy link
Author

today i got a new uuid folder:

dir .\.angular\cache\angular-webpack\ -r

    Directory: D:\servoy_inst\202112\developer\ws\.metadata\.plugins\com.servoy.eclipse.ngclient.ui\target\.angular\cache\angular-webpack

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          10-12-2021    12:02                00c6f86ad9c4b0ac77d5832867ecc1e127725cb3
d----           9-12-2021    17:29                452f48df2f16eff7f35d217be73a1e17c8ec5851

    Directory: D:\servoy_inst\202112\developer\ws\.metadata\.plugins\com.servoy.eclipse.ngclient.ui\target\.angular\cache\angular-webpack\0
0c6f86ad9c4b0ac77d5832867ecc1e127725cb3

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          10-12-2021    12:02      183781752 0.pack
-a---          10-12-2021    12:02      291742569 1.pack
-a---          10-12-2021    12:02       11290539 2.pack
-a---          10-12-2021    12:02        8089879 index.pack
-a---          10-12-2021    12:01        6896611 index.pack.old

    Directory: D:\servoy_inst\202112\developer\ws\.metadata\.plugins\com.servoy.eclipse.ngclient.ui\target\.angular\cache\angular-webpack\4
52f48df2f16eff7f35d217be73a1e17c8ec5851

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           9-12-2021    17:22      217749179 0.pack
-a---           9-12-2021    17:28      278296822 1.pack
-a---           9-12-2021    17:22        9778010 2.pack
-a---           9-12-2021    17:29            149 3.pack
-a---           9-12-2021    17:29        4769605 4.pack
-a---           9-12-2021    17:29        7874619 index.pack
-a---           9-12-2021    17:28        7874590 index.pack.old

and before of that it almost doubled it again (now its around 1GB in total)
and yes some installs did happen. (besides some builds)

What i don't fully understand is that a build makes it constantly grow
Why is the first build not generating stuff but the second build (of no packages are changed) is not just reused the cache (where it is made for i guess in the first place)

And i guess if a new package install is done (or what ever makes kind of the cache invalid) it would be nice to then first auto clean the cache..

@alan-agius4
Copy link
Collaborator

The new UUID is expected.

The cache key changed because of a new release, which results in the old cache to stale. I think in this case we should do an automatic clean for known stale directories. This is something that we can potentially do.

Regarding the additional pack file when no files have been changed. This shouldn't happen, I was able to replicate it but so far I haven't narrowed down whats the problem and if a bug in the Angular CLI or Webpack.

@alan-agius4 alan-agius4 self-assigned this Dec 10, 2021
@alan-agius4 alan-agius4 added needs: investigation Requires some digging to determine if action is needed and removed needs: more info Reporter must clarify the issue labels Dec 10, 2021
@alan-agius4
Copy link
Collaborator

I have debugging this a bit and there are 2 root causes of extra pack files when files have not changed.

  1. Using webpack's ProgressPlugin with MiniCssExtractPlugin causes the first pack to be invalidated. (Using ProgressPlugin with MiniCssExtractPlugin causes FS cache pack to be invalidated webpack/webpack#14946)
  2. When the cache is restored we are causing unneeded module rebuilds for files that have not been changed.
    new Promise<void>((resolve) => compilation.rebuildModule(webpackModule, () => resolve()));

@ngbot ngbot bot added this to the needsTriage milestone Dec 11, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Dec 11, 2021
@alan-agius4 alan-agius4 removed needs: investigation Requires some digging to determine if action is needed area: @angular-devkit/build-angular labels Dec 11, 2021
dgp1130 pushed a commit that referenced this issue Jan 12, 2022
…ache entries

With every build-angular release, previously created cache entries get stale and are no longer used. This causes the cache to keep growing as older files are not purged.

With this change we automatically purge entries that have been created with older version of build-angular and can no longer be used with the current installed version.

Closes #22323

(cherry picked from commit 6d2087b)
dgp1130 pushed a commit that referenced this issue Jan 12, 2022
…ache entries

With every build-angular release, previously created cache entries get stale and are no longer used. This causes the cache to keep growing as older files are not purged.

With this change we automatically purge entries that have been created with older version of build-angular and can no longer be used with the current installed version.

Closes #22323
@jcompagner
Copy link
Author

nice that it is fixed. i will try a new release asap to see how it behaves now
i just checked my current dir using 13.0.3 of CLI and it is 15GB....

@dgp1130
Copy link
Collaborator

dgp1130 commented Jan 12, 2022

@jcompagner, this should be included in 13.1.3 which I should get out later today.

@jcompagner
Copy link
Author

ok this is way better..

i didn't delete my 15GB cache dir, just let the latest release run on top of that, and yes it fully cleared it.
The cache dir did go down to around 330MB, and it didn't grow when i run over and over again build (none production)
And i have a feeling that it now really uses the cache because after the first run the second runs are as far as i can see now way faster (i didn't fully test this but it could be half of the time for me)

then i did run a production build and the cache did grow to 490MB (i did see an extra dir in angular-webpack)
the first run took 66seconds and the second run only took 25 seconds after that, and also here multiply runs didn't let the cache dir grow.

(and also no subresourceIntegrity warnings anymore ;) )

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants