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

More efficient implementation when conditionally stripping typename from variables #10890

Merged
merged 7 commits into from
May 18, 2023

Conversation

jerelmiller
Copy link
Member

#10853 introduced the ability to remove __typename from variables with an option to keep __typename at specific variable paths.

There was a question of whether we might be able to provide a more efficient way of handling this logic that would avoid the temporary array creation.

This PR introduces an alternate implementation that avoids some of the performance pitfalls of the initial implementation.

After running some benchmarks with a large data set (~2MB), this new implementation is about twice as fast as the old. Running this logic 5000 times with the old implementation took about 50s while the new implementation takes about 26s.

This PR also includes some additional tests for the removeTypenameFromVariables link that ensures it works with variables that do not include __typename.

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@changeset-bot
Copy link

changeset-bot bot commented May 17, 2023

⚠️ No Changeset found

Latest commit: 359f80a

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

@github-actions
Copy link
Contributor

github-actions bot commented May 17, 2023

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 35.83 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 45.45 KB (-0.24% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 34.05 KB (0%)
import { ApolloProvider } from "dist/react/index.js" 1.05 KB (0%)
import { useQuery } from "dist/react/index.js" 4.55 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 4.87 KB (0%)
import { useMutation } from "dist/react/index.js" 2.72 KB (0%)
import { useSubscription } from "dist/react/index.js" 2.55 KB (0%)
import { useSuspenseQuery_experimental } from "dist/react/index.js" 3.72 KB (0%)
import { useBackgroundQuery_experimental } from "dist/react/index.js" 3.15 KB (0%)
import { useReadQuery_experimental } from "dist/react/index.js" 1.25 KB (0%)
import { useFragment_experimental } from "dist/react/index.js" 1.98 KB (0%)

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

I'm glad this idea ended up being worth pursuing! Thanks for following up on it @jerelmiller.

@jerelmiller jerelmiller force-pushed the remove-typename-alternate-impl branch from d67cc66 to 785f68d Compare May 18, 2023 16:04
@jerelmiller jerelmiller merged commit d694ff4 into release-3.8 May 18, 2023
@jerelmiller jerelmiller deleted the remove-typename-alternate-impl branch May 18, 2023 19:19
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants