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

unnecessary updates when mutations are issued in rapid succession #4077

Closed
akiran opened this issue Oct 30, 2018 · 5 comments
Closed

unnecessary updates when mutations are issued in rapid succession #4077

akiran opened this issue Oct 30, 2018 · 5 comments
Labels
🚧 in-triage Issue currently being triaged

Comments

@akiran
Copy link
Contributor

akiran commented Oct 30, 2018

We have a live edit feature where we send mutation request on every key change.
We noticed a issue when we type fast and send mutation requests in rapid succession

Lets say we type 4 characters very fast. update method passed to mutation should be executed 8 times (4 times for optimistic response and 4 times for actual mutation response). But we noticed that update method is executed more than 8 times. I think, this is causing us a performance issue.

I replicated the issue in this repo
https://github.com/akiran/apollo-mutation-issue

This demo has an input field which send mutation on every key change. I added 10 sec delay on server to delay mutation response.
When I type 4 character quickly (let say "john"), 4 optimistic updates will execute first because of 10 second delay on mutation response. Then mutation response update start happening.

In ideal scenario, only 1 update related to mutation response should be executed because response from previous requests can be ignored and update for only final response can be executed

But because of some bug, 10 updates are executed (4 optimistic and 6 mutation response updates)

Let me know if more information is required related to this issue

Versions
System:
OS: macOS High Sierra 10.13.6
Binaries:
Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
Yarn: 1.10.1 - ~/.nvm/versions/node/v8.12.0/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
Browsers:
Chrome: 70.0.3538.77
Firefox: 60.0.1
Safari: 12.0
npmPackages:
apollo-boost: ^0.1.19 => 0.1.19
apollo-server: ^2.1.0 => 2.1.0
react-apollo: ^2.2.4 => 2.2.4

@benjamn
Copy link
Member

benjamn commented Oct 31, 2018

Thanks for the reproduction! When I run the app with npm start, it starts up at localhost:3000, but it looks like it's trying to connect to a server at localhost:4000. How should I start that server?

@akiran
Copy link
Contributor Author

akiran commented Nov 1, 2018

@benjamn You can start server with npm run server

@benjamn
Copy link
Member

benjamn commented Nov 2, 2018

Ok, I'm fairly certain this behavior was introduced by my commit d6a673f, which removed the behavior of silencing broadcasts when previousResult === newData.result, because that's not a safe way to tell whether the data have changed, so it's better to broadcast the data than to silence the broadcast.

In this specific case, the new behavior means that this.broadcastWatches() in the InMemoryCache#removeOptimistic method now actually broadcasts watches, even if the optimistic data have not changed.

I'm not sure how best to fix this, but it would probably break #3992 again if we went back to silencing these broadcasts, so that's not really an option.

@joe-re
Copy link
Contributor

joe-re commented Nov 2, 2018

@benjamn
I might have misunderstood, but I feel we should keep object mutability when update caching object.
Specifically, I think, we should use items = items.concat[addedItem] instead of items.push(item).
That assumption is the same on react, args of this.setState should keep mutability.
So I feel, I prefer previous working to currently.

@hwillson
Copy link
Member

hwillson commented Jul 9, 2019

This should no longer be an issue with current versions of apollo-client. Thanks!

@hwillson hwillson closed this as completed Jul 9, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚧 in-triage Issue currently being triaged
Projects
None yet
Development

No branches or pull requests

4 participants