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

Don't fire any query observables if the query result didn't change #402

Merged
merged 7 commits into from
Jul 18, 2016

Conversation

Poincare
Copy link
Contributor

@Poincare Poincare commented Jul 14, 2016

This PR makes it so that observables are only fired when the data received changes. This means that observers will only be fired if there's an updated result in the store. We do a deep diff before doing this. Solves #400.

I ran a comparison using the Chrome CPU profiler with and without this particular changeset on the Galaxy UI.

Before:
here

After:
Here

There is a single large element on this page that isn't changing in this particular query. As you can see clearly in the "before", this element is rendered for no reason and this rendering is eliminated in the "after". Secondly, there is also consistently reduced time to render the list of items that are changing since some of them don't actually change (~80ms to ~40ms). This isn't a particularly complex page so the performance improvements aren't incredible but it is easy to imagine cases where polling queries would be needlessly causes re-renders within React.

TODO:

  • Update CHANGELOG.md with your change
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@stubailo
Copy link
Contributor

I wouldn't call this "diffing", we should probably come up with a new name. At the end of the day, this can be summarized as "don't fire any query observables if the query result didn't change."

@Poincare Poincare changed the title Data diffing Don't fire any query observables if the query result didn't change Jul 14, 2016
// Given a query id and a new result, this checks if the old result is
// the same as the last result for that particular query id.
private isDifferentResult(queryId: string, result: ApolloQueryResult): boolean {
return !isEqual(this.queryResults[queryId], result);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will work in all cases right? Don't you need to use deepEqual?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nvm, this is deep

@stubailo stubailo self-assigned this Jul 18, 2016
@stubailo stubailo merged commit 37775ad into master Jul 18, 2016
@stubailo stubailo removed the ready label Jul 18, 2016
@stubailo stubailo deleted the data_diffing branch September 20, 2016 03:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants