perf(gatsby): more efficient parent-child check through arrays #22126
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.
This replaces a
_.uniq
with a.includes
which is calledN
times, once for each node, while the array of nodes is building up (or on the full set even?). The only reason, I think, is to make sure the newly inserted child does not already exist in the array of children. Theincludes
simply does a subset of thingsuniq
does.Another change is that a new array is no longer created;
parent.children
remains the same array reference after this step now.Addresses a problem surfaced by @tsriram in #21447
Drops the
source and transform
step by about 33% at scale. This step in a benchmark of 100k pages drops from 30s to 20s, a 150k pages bench drops from 45s to 30s.This is the long hanging fruit. There's still a lot of room for improvement.