-
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
optimisticResponse is changing all immutable objects on query #4141
Comments
Seeing the exact same behavior. It defeats the purpose of optimistic UI in the first place because rerensering all items can crush performance. |
Don't know if this is related but when I use optimisticResponce the cache (InMemoryCache) grows every time a mutation is done. When using a whole lot of queries it grows so bad that after about 15 Updates chrome crashes... |
Any news about this issue? Seeing the exact same behavior :/ |
+1 same problem here. |
Please, someone? |
I made a reproduction (https://codesandbox.io/s/apollo-client-issue-4141-lxib0) and found out what causes the issue. The reproduction renders a list of two people using a If no
However, if an
I think the problem is that optimistic updates use their own apollo-client/src/cache/inmemory/entityStore.ts Lines 397 to 398 in 23b17fa
I changed the second line to |
Any update on this? |
After a lot of thinking over the past few months, I believe The general idea is to perform canonicalization (sometimes called internalization) as a post-processing step, which happens to be a feature of the Canonicalization can be performed in O(|result|) time, but the Avoiding memory leaks in a system like this is a challenge, but one I understand pretty well by now. Ultimately, this trick should also limit the total amount of memory Apollo Client needs to retain, since deeply equal subtrees share a single canonical representation. Finally, while canonical objects are valuable and worth retaining, they are not irreplaceable—the cache could jettison its canonical object pool at any time to reclaim that memory, at the cost of losing the This is definitely too big of a change for Apollo Client v3.3, which we're hoping to finalize today, but I think we can get this into a v3.4 beta release soon! |
@benjamn amazing! Thanks for the detailed update! Sounds really promising. |
Awesome! |
My implementation of #4141 (comment) in #7439 is now available for testing in |
This change reduced the rendering time of a large component in my app by about 50%. Thanks, @benjamn! 😊 |
Same for us, we noticed a large improvement in performance with this change 🎉 Thank you @benjamn! |
This is awesome @benjamn ; I scanned the PR just for curiosity and really like how elegant it looks. I had a naive question, I was kind of surprised, it looks like most of the canonicalization changes were on the With the disclaimer that I really know very little about the internal client impls details, my concern specifically for the optimistic response case is that our flow (for this bug) was (or will be) something like:
Which is great, insofar as we get back stable identities for all leaves now, but my worry is the extra work that Basically is the core issue here that optimistic cache updates are still (?) deeply changing identities when they don't really need to? And yeah, fixing that back up in read from store is great (and faster than a React re-render penalty), but it could be even faster/cheaper for I also admit: a) this is an internal/perf impl detail b/c the bug is no longer observable, which is great Anyway, feel free to just scan/sanity check/not think too deeply about this, just wanted to type it out if anything for my own understanding. Thanks for the great work! |
@stephenh I owe you a longer answer, but I agree #7439 hides the referential identity churn without really addressing the underlying reasons for that churn. Specifically, because of the Even with #7439 in place, I think it makes sense to keep working on this issue from the other direction. After a couple days of investigation, I think I have a solution that involves removing most of the |
Not at all! Your description of an optimistic write creating its own separate-ish cache makes a lot of sense, in terms of needing a non-canonical staging area for its data, and why this would (pre #7439) be causing identity changes. And is plenty sufficient for my "just a user building a mental model" purposes. Great to hear you've got a plan for optimizing specifically the optimistic read/write side of things; really impressive, thanks! |
I have a watched query and I use optimisticResponse in a mutation to update only one object from this query:
When I use mutation with optimisticResponse like that, my whole pure list update (all itens on my watchedQuery changes). When I remove optimisticResponse only my changed item on list is updated.
Is this expected?
The text was updated successfully, but these errors were encountered: