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

potential optimization - bail out of executeSubSelectedArray calls #11670

Merged
merged 6 commits into from Mar 26, 2024

Conversation

phryneas
Copy link
Member

This just came up in #11669 and I wanted to try it out.

One thing to consider strongly here is that this returns the original empty array, so I'll have to investigate if that could make it out of the cache where users could accidentally start manipulating it (and if we see this as a problem).

We could have a "weak empty array mapping cache" somewhere to prevent that, but at that point I'm not sure if this optimization does make any sense at all.

Copy link

changeset-bot bot commented Mar 14, 2024

🦋 Changeset detected

Latest commit: aa388af

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 Patch

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

@phryneas
Copy link
Member Author

/release:pr

Copy link
Contributor

github-actions bot commented Mar 14, 2024

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 38.4 KB (+0.02% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 46.23 KB (+0.01% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 43.79 KB (+0.02% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 33.96 KB (+0.03% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 31.87 KB (+0.02% 🔺)
import { ApolloProvider } from "dist/react/index.js" 1.23 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.22 KB (0%)
import { useQuery } from "dist/react/index.js" 5.26 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.35 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.5 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.58 KB (0%)
import { useMutation } from "dist/react/index.js" 3.51 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.73 KB (0%)
import { useSubscription } from "dist/react/index.js" 3.19 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 2.38 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.41 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.07 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 4.89 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.55 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.02 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 3.68 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.17 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.11 KB (0%)
import { useFragment } from "dist/react/index.js" 2.27 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.22 KB (0%)

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-11670-20240314104411

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.

This looks safe to me. The StoreReader often returns fieldValue to application code without making a defensive copy, but frozen (in development), so copying fieldValue in this case seems unusual/unnecessary.

Comment on lines 406 to 409
fieldValue =
fieldValue.length === 0 ?
fieldValue
: handleMissing(
Copy link
Member

Choose a reason for hiding this comment

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

You could probably rearrange this so it only calls handleMissing and updates fieldValue if fieldValue.length > 0, but I leave that 🏌️ up to you.

@github-actions github-actions bot added the auto-cleanup 🤖 label Mar 14, 2024
@phryneas phryneas marked this pull request as ready for review March 25, 2024 11:17
@phryneas phryneas linked an issue Mar 25, 2024 that may be closed by this pull request
Copy link

netlify bot commented Mar 25, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 8c6860c
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/66015c6b62452e000841cf24
😎 Deploy Preview https://deploy-preview-11670--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 25, 2024

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit aa388af
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/66015d0d85af5a00082c2cf9
😎 Deploy Preview https://deploy-preview-11670--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

Nice! 🎉

@phryneas phryneas merged commit cc5c03b into main Mar 26, 2024
29 checks passed
@phryneas phryneas deleted the pr/optimize-executeSubSelectedArray-calls branch March 26, 2024 09:15
@github-actions github-actions bot mentioned this pull request Mar 26, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 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.

executeSubSelectedArray cache is full of empty arrays
3 participants