fix(gatsby): rewrite a spread that would break at scale #28910
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Do not spread all the nodes of a particular type on a function call. When the set of nodes exceeds 64k elements you'll see stack overflow errors. This PR rewrites it such that the spread is no longer necessary. (The new spread is going to be one or a very low number since you're not going to have thousands of types in a Gatsby site unless you're trying hard for it)
This was blocking images at scale. However, the image stuff no longer goes through this path after #28891 but this function should still not spread potentially thousands of nodes.
I tested a few strategies and then picked the one in this PR because it was the least invasive to the code base while being about equal in performance. Tested against an 8k image benchmark that hit this path six times for every image (before the aforementioned PR). Note: In this test, the type count was always 1 (
'File'
).