Build is extremely slow at the end

At the very end of the build:

5:12:42 PM: Finished saving rust rustup cache
5:12:42 PM: Started saving go dependencies
5:12:42 PM: Finished saving go dependencies
5:12:42 PM: Build script success
5:25:35 PM: Finished processing build request in 22m2.84690907s

What is taking 13 minutes there? This has bloated my build a lot!

Also this:

5:05:57 PM: Started restoring cached yarn cache
5:10:20 PM: Finished restoring cached yarn cache

Why is yarn cache restore is taking 5 minutes?

I can install it from npm faster than that!

Is there a way to disable yarn cache?

Hey there, @moltar :wave:

Welcome to the Netlify Forums and thanks reaching out. There are multiple reasons why a build may be taking a bit of time, so we will need a bit more information in order to look into this.

Can you please share the following:

  1. A full copy of your most recent deploy log
  2. A link to your site
  3. You project repo, if public
  4. If not public, can you please share your package.json file or your .toml file?

Lastly, this is a good resource that covers optimizing your build time:

Thanks so much.

We’ve also found cache to be slower than a cache-free install with yarn. In some cases using the cache almost doubles our total build time. Our latest comparison resulted in a cache build at 7m 42s, cache-free 4m 13s.

I don’t know that I’ve seen the cache make things faster, and over time gradually slows the build down even more.

My guess as to why this happens is the cache keeps growing in size as modules are upgraded, and the cache keeps the old versions around.

It would be nice if the cache was faster, or there was an option to turn off the cache. Customers would get faster builds, and Netlify wouldn’t be paying the extra price for longer builds/unnecessary storage.

thanks for that feedback, @rbergfalk i’ll pass it on.

1 Like

Yeah, recently did a lot of experiments with AWS CodeBuild and also came to the same conclusion. Even at AWS scale, pulling cache from S3, within the same region, extracting it, linking and all of that jazz is slower by a magnitude of x2 than just doing β€œyarn install”.

My guess is that pulling many small files in parallel is just somehow faster than pulling one monolith of a cache.

Our cache size was ~ 800MB

Hey @moltar and @rbergfalk,

I hear you both, but what you both are experiencing is probably coming from environments that you’re trying to test. You’ve your own code bases, your own set of dependencies, and other stuff, but we also have a lot more users who are having faster builds due to cache. I’m not saying it’s just the two of you with this issue, no, we’ve had such requests in the past, but each site is different and has different requirements. So it’s difficult to target all in one go.

The only possible solution I see to this is to provide an option to users to disable the build cache so that caching is not forced. Is that it or do you have any other suggestions? Also, at the moment, you can use the Netlify API to trigger builds without cache. Would that work for your use cases?

On a side note, I think there’s a possible workaround for you all till then. You can configure the build command to delete your node_modules, your repo, and other directories after your build command. If these directories won’t exist, they won’t end up in cache.

Thanks @hrishikesh

I don’t think our environment is that special. Its a typical create-react-app, typescript, jest, storybook, MUI project with some additional modules. Granted all the dependencies do come in kind of heavy. Our cache is also around 800MB - 900MB like @moltar.

Having an option to disable cache in config would be helpful on our end.

I’m not sure we’ll go the API route just yet. If we go down that path we’d probably invest in building outside of netlify too.

We’ll give deleting node modules a shot.

I gave clearing node_modules a shot, but it caused an issue as it seems node_modules are required for the deployment script? Our build errors out with

3:25:37 PM: ────────────────────────────────────────────────────────────────
3:25:37 PM:   2. Functions bundling                                         
3:25:37 PM: ────────────────────────────────────────────────────────────────
3:25:37 PM: ​
3:25:37 PM: Packaging Functions from netlify/functions directory:
3:25:37 PM:  - deploy-succeeded.js
3:25:37 PM: ​
3:25:37 PM: ​
3:25:37 PM: ────────────────────────────────────────────────────────────────
3:25:37 PM:   Dependencies installation error                               
3:25:37 PM: ────────────────────────────────────────────────────────────────
3:25:37 PM: ​
3:25:37 PM:   Error message
3:25:37 PM:   A Netlify Function failed to require one of its dependencies.
3:25:37 PM:   Please make sure it is present in the site's top-level "package.json".
3:25:37 PM:   In file "/opt/build/repo/netlify/functions/deploy-succeeded.js"
3:25:37 PM:   Cannot find module 'axios'
3:25:37 PM:   Require stack:
3:25:37 PM:   - /opt/buildhome/node-deps/node_modules/@netlify/zip-it-and-ship-it/dist/runtimes/node/bundlers/zisi/resolve.js

Hey @rbergfalk,

When I said you need to clear node_modules, I didn’t mean to ask you to do it during the build command. I should have specified better. So you could create a build plugin, and use something like cache utils: Create Build Plugins | Netlify Docs, to delete the cache.

1 Like