[Need Help] Drastic increase in build times, and new cache/adapter behavior

Hi !

For context :

  • We have a Gatsby site hosted on Netlify. We migrated from Gatsby Cloud in October 2023.
  • Once on Netlify, typical build times were ~4 minutes, or 20-25 minutes if the cache was cleared.
  • We use headless Wordpress.

Our dependencies :

"dependencies": {
		"@hubspot/api-client": "^9.0.0",
		"@loadable/component": "^5.14.1",
		"@netlify/functions": "^2.0.2",
		"@svgr/webpack": "^5.5.0",
		"@u-wave/react-vimeo": "^0.9.10",
		"clsx": "^1.2.1",
		"cross-env": "^7.0.2",
		"gatsby": "^5.12.11",
		"gatsby-adapter-netlify": "^1.0.0",
		"gatsby-plugin-alias-imports": "^1.0.5",
		"gatsby-plugin-catch-links": "^5.9.0",
		"gatsby-plugin-feed": "^5.12.3",
		"gatsby-plugin-gatsby-cloud": "^5.9.0",
		"gatsby-plugin-google-tagmanager": "^5.9.0",
		"gatsby-plugin-image": "^3.9.0",
		"gatsby-plugin-manifest": "^5.12.3",
		"gatsby-plugin-meta-redirect": "^1.1.1",
		"gatsby-plugin-offline": "^6.9.0",
		"gatsby-plugin-react-helmet": "^6.9.0",
		"gatsby-plugin-remove-serviceworker": "^1.0.0",
		"gatsby-plugin-sass": "^6.9.0",
		"gatsby-plugin-sharp": "^5.12.3",
		"gatsby-plugin-sitemap": "^6.9.0",
		"gatsby-plugin-split-css": "^2.0.0",
		"gatsby-plugin-svgr": "^3.0.0-beta.0",
		"gatsby-plugin-why-did-you-render": "^2.0.0",
		"gatsby-remark-images": "^7.9.0",
		"gatsby-source-apiserver": "^2.1.3",
		"gatsby-source-filesystem": "^5.9.0",
		"gatsby-source-wordpress": "^7.12.0",
		"gatsby-transformer-json": "^5.11.0",
		"gatsby-transformer-remark": "^6.9.0",
		"gatsby-transformer-sharp": "^5.12.3",
		"graphql": "^16.6.0",
		"i18n-react": "^0.7.0",
		"prop-types": "^15.7.2",
		"react": "^18.2.0",
		"react-calendly": "^4.3.0",
		"react-cookies": "^0.1.1",
		"react-countup": "^4.2.3",
		"react-dom": "^18.2.0",
		"react-helmet": "^6.1.0",
		"react-hubspot-form": "^1.3.7",
		"react-responsive-carousel": "^3.1.51",
		"react-scroll": "^1.7.14",
		"react-share": "^4.2.0",
		"react-sticky": "^6.0.3",
		"react-swipeable": "^6.1.0",
		"react-transition-group": "^4.4.2",
		"react-youtube": "^7.13.1",
		"request": "^2.88.2",
		"sass": "^1.54.3",
		"typescript": "^4.9.5"
	},

A few potentially relevant configs :

plugins: [
	...
	{
		resolve: "gatsby-plugin-sharp",
		options: {
			defaultQuality: 80,
			stripMetadata: true,
			defaults: {
				formats: ["auto", "webp" /* , "avif" */],
				placeholder: "blurred",
				quality: 80,
				breakpoints: [600, 1088],
			},
		},
	},
	...
	{
		resolve: "gatsby-source-wordpress",
		options: {
			url: `${process.env.WP_URL}/graphql`,
			verbose: true,
			debug: {
				graphql: {
					writeQueriesToDisk: true,
				},
			},
			html: {
				imageMaxWidth: 1088,
				generateWebpImages: true,
				generateAvifImages: false,
				placeholderType: "blurred",
			},
			production: {
				hardCacheMediaFiles: true,
			},
			develop: {
				hardCacheData: true,
				hardCacheMediaFiles: true,
			},
			schema: { timeout: 50000 },
			type: {
				Post: { limit: process.env.LIMIT_WP_POSTS === "true" ? 100 : 10000 },
				MediaItem: {
					excludeFieldNames: [
						"contentNodes",
						"seo",
						"ancestors",
						"author",
						"template",
						"lastEditedBy",
						"authorDatabaseId",
						"authorId",
						"contentTypeName",
						"dateGmt",
						"desiredSlug",
						"enclosure",
						"isContentNode",
						"isTermNode",
						"modified",
						"modifiedGmt",
						"parentDatabaseId",
						"parentId",
						"srcSet",
						"parent",
						"children",
					],
				},
				Comment: { exclude: true },
				Menu: { exclude: true },
				MenuItem: { exclude: true },
			},
		},
	},
	...
],

The Issue

Our build times have jumped from the typical ~4 minutes to a constant 25+ minutes, and depending on branches it often fails due to time limits. It seems to have started around Dec 6, but I’m not sure, different branches have started misbehaving at different dates.

3 things that I notice that are new

  1. I get messages from gatsby-adapter-netlify that I didn’t get before. Namely, at the end of the build phase, I get :
4:25:32 PM: info Done building in 631.164070789 sec
4:25:43 PM: info [gatsby-adapter-netlify] Stored the Gatsby cache to speed up future builds. 🔥
4:33:59 PM: ​
4:33:59 PM: (build.command completed in 18m 58.4s)

Notice the time stamps. After saying “Stored the Gatsby cache to speed up future builds”, nothing happens for about 10 minutes. And then the build actually completes. That alone, could almost account for the whole extra build time, but I don’t know how to debug it.

  1. I started noticing it on our Staging branch, which obviously has the latest updates etc. But since, the issue seems to have “spread” to other installs pulling from other branches, some of which haven’t been merged with Staging in weeks. I even created a whole new test install, pulling from a branch that was last touched on Nov 7, and the same issue applies. That would seem to indicate that the issue is either with WP or with Netlify, but again, not sure how to debug that.

  2. Pretty much every build seems top reset the cache. I get all of these messages in the log like 95% of the time :

11:32:43 AM: build-image version: 3ffff9df3d5419545acc1b673a54de348174406d (focal)
11:32:43 AM: buildbot version: 4613af4169363e3b38cfadfa4665d34cd1d1427b
11:32:43 AM: Fetching cached dependencies
11:32:43 AM: Starting to download cache of 4.0GB
11:33:34 AM: Finished downloading cache in 51.382s
11:33:34 AM: Starting to extract cache
11:33:45 AM: Finished extracting cache in 10.986s
11:33:46 AM: Finished fetching cache in 1m2.662s
...
9:12:59 AM: info [gatsby-adapter-netlify] Found a Gatsby cache. We"re about to go FAST. ⚡
success load plugins - 1.745s
9:13:00 AM: warning gatsby-plugin-react-helmet: Gatsby now has built-in support for modifying the document head. Learn more at https://gatsby.dev/gatsby-head
9:13:00 AM: success onPreInit - 0.006s
9:13:00 AM: success delete worker cache from previous builds - 0.001s
9:13:00 AM: info One or more of your plugins have changed since the last time you ran Gatsby. As
9:13:00 AM: a precaution, we"re deleting your site"s cache to ensure there"s no stale data.
success initialize cache - 0.187s
9:13:01 AM: success copy gatsby files - 0.321s
9:13:01 AM: success Compiling Gatsby Functions - 0.311s
9:13:01 AM: success onPreBootstrap - 0.335s
9:13:05 AM: success  gatsby-source-wordpress  ensuring plugin requirements are met - 3.098s
9:13:05 AM: ⠀
9:13:05 AM: info  gatsby-source-wordpress 
9:13:05 AM: 	This is either your first build or the cache was cleared.
9:13:05 AM: 	Please wait while your WordPress data is synced to your Gatsby cache.
9:13:05 AM: 	Maybe now"s a good time to get up and stretch? :D
9:13:07 AM: success  gatsby-source-wordpress  ingest WPGraphQL schema - 2.269s
9:13:07 AM: success createSchemaCustomization - 5.503s
9:13:08 AM: success  gatsby-source-wordpress  Comment - 0.725s - fetched 0

What I have tried

Reverting Gatsby : even reverting to commits/branches as far back as the initial migration to Netlify (mid-October) didn’t change anything. Thus I’m led to believe the issue is not with some code I would have written recently.

Reverting WP : I restored a backup dating Nov 7 for our staging WP and ran tests ; still take 25+ minutes to build, including on the Gatsby install from October. Thus I’m led to believe the issue is not with a change that would’ve happened with WP recently.

Re-launching builds, with and without clearing cache : gives me a pretty consistent 25+ minutes build if I clear the cache, or ~15 minutes if I launch a normal build without changing anything and as soon as the previous build is done.

Testing gastby build on my local computer : these issues do not show up ; no weird cache or adapter message, and builds take 5 minutes if I clear the cache, and 40 seconds if I don’t…

I don’t know what I’m hoping for, really… maybe that somebody else has experienced this and heard from Netlify that there were subtle changes made recently that may be the cause ? Or maybe somebody has a debug trick that I’m not aware of ? One thing for sure, our website is close to unusable right now and I have nowhere to turn for solutions. This is kind of a Hail Mary to try and fix it before the company goes on holiday break.

Thanks to anyone who can provide input !

Hi, @BSLK. I believe there is an open support ticket where we are troubleshooting this issue.

We’ll continue to follow-up there.