Incremental Gatsby Build time Increases

Hey there!

It looks like there are two significant bugs in the beta that are adding to the build times:

  1. currently, Node modules installed with Yarn are reinstalled on every build — this adds a whole bunch of extra time: Yarn install runs even when a node_modules cache is found · Issue #433 · netlify/build-image · GitHub
  2. installing build plugins automatically adds extra build time: Automatic installation of plugins makes build much slower · Issue #1137 · netlify/build · GitHub

I can’t say for sure without reviewing the logs, but my guess is that the actual Gatsby builds are faster, but the startup time for Netlify is slower due to these bugs (please correct me if I’m wrong).

These bugs will both end up getting fixed, so in time this will resolve itself. However, if you want to fix it on your own, you can make two changes and it should resolve this issue:

  1. Switch to npm for plugin installation. Delete the yarn.lock in your project and use npm install to generate a package-lock.json. Swap any uses of yarn out for npm (e.g. npm run build instead of yarn build) to make sure things work as expected.

    This will remove the double-install of packages, which in @sam.r’s case from the logs above would remove 4 minutes from the build.

  2. Install the build plugins manually. We automatically install build plugins as a convenience, but it’s adding additional time. You can avoid this added time if you add plugins as dependencies to your project:

    npm install netlify-plugin-gatsby-cache
    

These two fixes should remove the slowdowns and let you get the benefits of Gatsby incremental builds. Please report back if you try it so we can verify that there aren’t other things happening!

Thanks!

2 Likes