Every build fetches and extracts cached dependencies before proceeding. The time taken has grown substantially and monotonically over the lifetime of the project, from barely a few seconds to almost a minute and a half. What can I do to investigate why and reduce it?
Here’s an example:
2:36:13 PM: Fetching cached dependencies
2:36:13 PM: Starting to download cache of 1.7GB
2:36:28 PM: Finished downloading cache in 14.997130807s
2:36:28 PM: Starting to extract cache
2:37:35 PM: Finished extracting cache in 1m6.901284412s
2:37:35 PM: Finished fetching cache in 1m21.985620897s
Obviously, the first question is: are the project’s dependencies in fact that large? du -h node_modules
reports a total size of 1.3GB, which admittedly is not far off from the 1.7GB reported above. Nevertheless, I would like to understand what accounts for the difference.
Over the life of working on the project, I’ve only observed the reported size of the fetched dependencies to increase, never decrease. That’s true even after removing dependencies. Is it possible the cache is still including old dependencies that are no longer used? The project is a JS project using npm (not yarn).
Here are other things I’ve done so far:
- I ran a build that executed
du -a ../cache/
to inspect the contents of the build server cache directory. The cache directory only has 500mb of content. Surprisingly, I didn’t see my project’s node_modules there, only build server dependencies (node versions, pip, ruby, etc.) - Removed large dependencies from my project, ran “Clear cache and deploy site”, then ran it again using the dependency cache as normal. There was no change in the reported fetched cache size. (Granted, these builds failed because various function dependencies were missing, so if Netlify’s logic is to only cache dependencies on successful builds, that would explain why this experiment had no effect. But the build logs still do have a “Caching artifacts” section at the end, even on failed builds.)