-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Unreasonable heap size calling fetchMore, most prevalent with JavaScriptCore environments #5007
Comments
We are fairly certain this is a bug, but if it is expected behavior and a matter of refining/optimizing our query: here's a cross-reference to a Spectrum thread I started on the same topic (with a few other details as well): https://spectrum.chat/apollo/apollo-client/inmemorycache-inflates-drastically-calling-fetchmore-on-a-deeply-nested-query~17b06b40-5c53-4856-93c6-0948e768477f |
I’m still investigating this, but in the meantime could you try disabling result caching (the layer of caching on top of the normalized cache)? this.client = new ApolloClient({
link: concat(authMiddlewareLink, httpLink),
cache: new InMemoryCache({
freezeResults: true,
resultCaching: false, // add this option
}),
assumeImmutableResults: true
}); This will make repeated reads a bit slower, but should also make the cache use less memory. |
@jasongaare I can confirm my suggestion above seems to reduce memory usage in the reproductions you provided. Still working on a longer-term fix. |
Thank you for looking into this!
I, too, have seen improvements on Safari and the iOS simulator using However, at some point in the last few weeks hunting this down, I had tried using I've been using
A couple things here:
So if this is a viable solution in the short-term, what are the underlying reproductions of apollo-client/packages/apollo-cache-inmemory/src/inMemoryCache.ts Lines 119 to 124 in 7eaf413
so presumably it just removes the usage of the optimism library? Or perhaps there's more?
Thanks again for digging into this. |
That’s right, when |
@benjamn here's a couple other things we are noticing, and are curious if it is all related or not.
Here's some mobile memory usage data to back these up (Android device):
_Again, not sure if these are related or separate issues. If they are separate I can certainly open some other issues to keep this thread on-topic _ |
@jasongaare the android-jsc-buildscripts version of JavaScriptCore is already used in React Native 0.59 and newer. In fact, RN 0.59.10 bumps the JSC dependency to solve some issues reported by users. So, no need to build your own to get a newer one. Additionally, we are also using apollo-client in a React Native context. We haven't seen this particular problem yet, but reported our own major performance issue in #4991 . Thanks for reporting this detailed issue, I think it will help a lot of people having trouble with Apollo in React Native! 🥇 |
Please try a recent version of |
Intended outcome:
We've implemented a
<Query>
component that fetches 50 photos at a time from our database, along with information related to those photos. We expect as we callfetchMore
andupdateQuery
the JS heap would grow only in relation to the size of the response for the next 50 photosActual outcome:
As
fetchMore
gets called on our component, the heap size grows unreasonably, specifically on Safari and in our React Native app (the root issue!) - both of which use JavaScriptCore. Running our code in a V8 JS environment (read: Chrome) the heap grows at a more reasonable rate. (but perhaps still too much?) Here are some screenshots of heap snapshots on each browser, using the same query to fetch 250, 500, then 750 photos via pages of 50.Photos Query
Curiously, when we added an
@connection
directive things got worse...Photos Query with @connection
This issue is a blocker for our mobile app at the moment, as we are using React Native and are experiencing the drastic heap inflation with the shipped JSC version. We are currently on React Native 55.3, but have also tested on the latest version (which has a newer JSC) but are seeing the same results (aka still exists in new JSC versions, as demonstrated in the latest version of Safari above)
Further, we have also attempted to use the new immutable features in the cache/client as seen here (and on the reproductions below), but it did not improve results as we hoped it might
How to reproduce the issue:
Here are the reproductions with our production API and actual query we are running:
Photos Query
Photos Query with @connection
Versions
The text was updated successfully, but these errors were encountered: