Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-source-contentful): reduce memory usage #37910

Merged
merged 73 commits into from
Apr 18, 2023

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 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
Collaborator

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.

6 participants