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

Use a Set for referencers #3056

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Use a Set for referencers #3056

wants to merge 2 commits into from

Conversation

clenfest
Copy link
Contributor

When working with elements with many referencers, addReferencer() became very hot.

If you have eg. 100 referencers, each one is added one by one, and each new addition iterates the entire existing referencers list. This could cause quadratic performance.

This changes the _referencers values to be JS Sets. This maintains the same order for algorithms that rely on order.

When working with elements with many referencers, `addReferencer()` became very hot.
If you have eg. 100 referencers, each one is added one by one, and each
new addition iterates the entire existing referencers list. This could
cause quadratic performance.

This changes the `_referencers` values to be JS `Set`s. This maintains
the same order for algorithms that rely on order.
@clenfest clenfest requested a review from a team as a code owner June 28, 2024 17:57
Copy link

changeset-bot bot commented Jun 28, 2024

⚠️ No Changeset found

Latest commit: c65b400

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Jun 28, 2024

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit c65b400
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/667ef99c53902b0008bb729b

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Member

@dariuszkuc dariuszkuc left a comment

Choose a reason for hiding this comment

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

Approved.

Follow up question though -> should we also convert other array usages to sets? unionsWhereMember/allImplementations etc?

@goto-bus-stop
Copy link
Member

goto-bus-stop commented Jul 1, 2024

It actually might be good to convert unionsWhereMember and allImplementations, too. I didn't do it because it's more work. But allImplementations in particular is used for the runtimeTypesIntersect check, which is currently O(n^2), and could be O(n) if allImplementations used a Set. But maybe do that when we have an example query where it is very hot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants