Skip to content

Conversation

@TylerBarnes
Copy link
Contributor

@TylerBarnes TylerBarnes commented Apr 3, 2023

Along with #37782 and #37780 this PR allows a 4.9M node Contentful site to build with 24G of memory. Before these 3 PRs the site needed 64G memory and would OOM on data updates.

This PR does a few things:

  1. During any iteration on nodes there is code to prevent the event loop from being blocked. This included adding a queue for calling createNode so that the queue can pause as needed to not block. This lowers memory and also generally speeds up the sourcing process.

  2. While iterating through large lists, chunks of the list is set to undefined after being processed. This allows GC before the whole list is done being iterated on, keeping memory usage down.

  3. On every data update every existing node was loaded into memory and iterated on and then GC'd at the end of sourceNodes. This was to search and build up backreferences. In this PR I changed it so it stores the minimal info about nodes needed for back references and keeps it in memory between data updates. You'd think this would increase memory usage but it substantially decreases is while also massively speeding up data updates. For the 4.9M node site a data update would OOM after 10 minutes. Now it succeeds after 45s to 3 min (depending on the update).

TylerBarnes and others added 30 commits March 24, 2023 12:11
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* fix(gatsby): validate sub plugins options of gatsby-plugin-mdx

* revert hardcoded path to subplugins

* validate subplugins if they are not under 'options.plugins' field

---------

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
 - create-gatsby@3.9.0-next.1
 - gatsby-cli@5.9.0-next.1
 - gatsby-plugin-sharp@5.9.0-next.1
 - gatsby-transformer-sqip@5.9.0-next.1
 - gatsby@5.9.0-next.2
@TylerBarnes
Copy link
Contributor Author

@projectlandscapewebsite best things to do:

  1. Gatsby Cloud support
  2. Open a discussion in this repo about reducing memory usage for source-wordpress. In the discussion if you can provide a reproduction and a description of what's going on it will help spark discussion about what could possibly be done or what the cause might be

@TylerBarnes TylerBarnes requested a review from pieh April 17, 2023 18:01
@pieh pieh merged commit 311b202 into master Apr 18, 2023
@pieh pieh deleted the fix/contentful-memory-usage branch April 18, 2023 07:28
@axe312ger
Copy link
Contributor

Great! Thank you so much for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: performance Related to runtime & build performance topic: source-contentful Related to Gatsby's integration with Contentful topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants