Skip to content

Speed up yarn develop on warm restart#3391

Merged
zknill merged 1 commit into
mainfrom
zak/gatsby-build-time
May 29, 2026
Merged

Speed up yarn develop on warm restart#3391
zknill merged 1 commit into
mainfrom
zak/gatsby-build-time

Conversation

@zknill
Copy link
Copy Markdown
Contributor

@zknill zknill commented May 28, 2026

yarn develop previously ran gatsby clean before every start, so every run was a cold start: ~150s webpack bundle and ~130s sharp image processing for our ~500 MDX pages. Drop gatsby clean from develop so the babel-loader, terser, webpack, and sharp caches survive between runs, and add develop:clean as an escape hatch when a true reset is needed.

The reason develop previously required a clean is a Gatsby cache quirk: ExampleFile nodes are derived inside onCreateNode from parent File nodes sourced by gatsby-source-filesystem. On warm restart, Gatsby does not call onCreateNode for cached-unchanged parents, so the derived ExampleFile nodes are never touched and get removed by the stale-node GC. createPages then fails with "Examples result is undefined". Add a sourceNodes hook that touches every ExampleFile each build so they survive.

With derived-node GC fixed, GATSBY_EXPERIMENTAL_DEV_SSR is safe to enable; it lazy-compiles pages on demand and is the largest single win on warm restart. Earlier attempts blamed DEV_SSR for the missing nodes, but those failures were the same stale-GC bug presenting earlier.

Also restrict gatsby-plugin-sharp formats to ['auto'] in dev so cold image processing doesn't produce WebP variants we never look at locally (production unchanged), and set GATSBY_CPU_COUNT=physical_cores on dev scripts so sharp uses every physical core.

Measured locally: cold ~290s -> ~120s; warm restart ~17s end-to-end (previously not viable because of the cache bug).

`yarn develop` previously ran `gatsby clean` before every start, so every
run was a cold start: ~150s webpack bundle and ~130s sharp image
processing for our ~500 MDX pages. Drop `gatsby clean` from `develop` so
the babel-loader, terser, webpack, and sharp caches survive between
runs, and add `develop:clean` as an escape hatch when a true reset is
needed.

The reason `develop` previously required a clean is a Gatsby cache
quirk: ExampleFile nodes are derived inside onCreateNode from parent
File nodes sourced by gatsby-source-filesystem. On warm restart, Gatsby
does not call onCreateNode for cached-unchanged parents, so the derived
ExampleFile nodes are never touched and get removed by the stale-node
GC. createPages then fails with "Examples result is undefined". Add a
sourceNodes hook that touches every ExampleFile each build so they
survive.

With derived-node GC fixed, GATSBY_EXPERIMENTAL_DEV_SSR is safe to
enable; it lazy-compiles pages on demand and is the largest single win
on warm restart. Earlier attempts blamed DEV_SSR for the missing nodes,
but those failures were the same stale-GC bug presenting earlier.

Also restrict gatsby-plugin-sharp formats to ['auto'] in dev so cold
image processing doesn't produce WebP variants we never look at locally
(production unchanged), and set GATSBY_CPU_COUNT=physical_cores on dev
scripts so sharp uses every physical core.

Measured locally: cold ~290s -> ~120s; warm restart ~17s end-to-end
(previously not viable because of the cache bug).
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4adc1eb3-22d3-4163-ae96-8eae990a579b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch zak/gatsby-build-time

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zknill zknill requested a review from AndyTWF May 28, 2026 13:18
Copy link
Copy Markdown
Member

@kennethkalmer kennethkalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @zknill, thanks for making everyone's lives better here 🚀

@zknill zknill merged commit d3063ac into main May 29, 2026
7 checks passed
@zknill zknill deleted the zak/gatsby-build-time branch May 29, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants