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

QueryManager.inFlightLinkObservables: use a strong Trie #11345

Merged
merged 14 commits into from Dec 1, 2023

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Nov 6, 2023

Since @wryware/trie@0.5.0 now has a remove function, we can use that data structure in QueryManager.inFlightLinkObservables and shave off a few bytes here.

Should not be merged before we have a new optimism version

Before merging/releasing: add handling to @apollo/experimental-nextjs-app-support

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

Copy link

changeset-bot bot commented Nov 6, 2023

🦋 Changeset detected

Latest commit: 7fb21fa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Minor

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

github-actions bot commented Nov 6, 2023

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 37.79 KB (+0.16% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 44.26 KB (+0.16% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 42.75 KB (+0.18% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 32.87 KB (+0.25% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 31.55 KB (+0.29% 🔺)
import { ApolloProvider } from "dist/react/index.js" 1.28 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.26 KB (0%)
import { useQuery } from "dist/react/index.js" 4.38 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.19 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 4.69 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.51 KB (0%)
import { useMutation } from "dist/react/index.js" 2.65 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.63 KB (0%)
import { useSubscription } from "dist/react/index.js" 2.34 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.29 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 4.37 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 3.79 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 3.86 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.27 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 4.12 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.53 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.05 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3 KB (0%)
import { useFragment } from "dist/react/index.js" 2.15 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.1 KB (0%)

@jerelmiller
Copy link
Member

@phryneas just to clarify the intent of this change, is this strictly to shave off some bytes from the end build size, or will this have a memory impact as well since the printed query string can now be shared for multiple variables in the Trie? Would love to have a quick "why" in the changeset to describe the impact of this change so end users understand how this will positively impact them when upgrading. Thanks!

@phryneas
Copy link
Member Author

phryneas commented Nov 6, 2023

@jerelmiller This is really just a "shaving off bytes" - the structure was a Map of Maps before and is a Map of Maps (in the form of a Trie) now. Thing is, we add slightly more bundle size as the Trie implementation now has a remove method, so we can try to counteract that by using the Trie implementation where it saves a bit of code - and here, we essentially had a hand-written Trie in our sourcecode.

=> Implementation changes, but no observable behaviour will change in any way. That will happen in other places where we will use the new remove method (e.g. SuspenseCache).

@jerelmiller
Copy link
Member

@phryneas thats helpful to understand! Appreciate the context here :)

@phryneas phryneas added this to the MemoryAnalysis milestone Nov 9, 2023
@phryneas phryneas added the auto-cleanup 🤖 label Nov 17, 2023
@phryneas
Copy link
Member Author

/release:pr

Copy link
Contributor

A new release has been made for this PR. You can install it with npm i @apollo/client@0.0.0-pr-11345-20231129141218.

@phryneas
Copy link
Member Author

/release:pr

Copy link
Contributor

A new release has been made for this PR. You can install it with npm i @apollo/client@0.0.0-pr-11345-20231129164802.

@phryneas
Copy link
Member Author

phryneas commented Nov 30, 2023

I've fixed up some tests, added a runtime warning if used with oudated versions of @apollo/experimental-nextjs-app-support, and had some minor code changes to ensure compatibility.

Requesting a re-review for that reason :)

You can see these changes here:

https://github.com/apollographql/apollo-client//compare/4d6e8c3c0421c2c8ed268c6cb4231948c195dd0f...0cbdfcc71e8c9edba3e9d7eca1e5548435beee07

On the other side, I've opened the PR apollographql/apollo-client-nextjs#144 to accommodate for the changes in this PR. Please give it a review, too :)

Comment on lines +187 to +194
// TODO: remove before we release 3.9
Object.defineProperty(this.inFlightLinkObservables, "get", {
value: () => {
throw new Error(
"This version of Apollo Client requires at least @apollo/experimental-nextjs-app-support version 0.5.2."
);
},
});
Copy link
Member Author

Choose a reason for hiding this comment

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

You can see this work out over in apollographql/apollo-client-nextjs#144 (comment)

Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Thanks for catching that update to the Next.js package!

@phryneas phryneas merged commit 1759066 into release-3.9 Dec 1, 2023
22 checks passed
@phryneas phryneas deleted the pr/inFlightLinkObservables-trie branch December 1, 2023 10:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants