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

Investigate GraphQL dedupe optimizations #592

Closed
stephenh opened this issue Mar 29, 2023 · 1 comment
Closed

Investigate GraphQL dedupe optimizations #592

stephenh opened this issue Mar 29, 2023 · 1 comment

Comments

@stephenh
Copy link
Collaborator

The difference between, top-level queries:

query {
  bookReviews {
    book { author { name } }
  }
}

And subgraph queries:

query {
  authors {
    name
    books { bookReviews { ... } }
  }
}

Can be surprisingly large due to the duplication of author { name } that is from the top-level query.

In particular we've seen, for returning the same data set:

  • 60% bigger payload (690kb vs. 1.1mb), and
  • 70% more JSON fields (22k vs 37k)

Which translates to more CPU time spent:

  1. Re-invoking duplicate resolvers (the same author.name every time)
  2. Re-invoking duplicate auth checks (the same author.name auth check multiple times)
  3. JSON.stringify-ing the payload
  4. gziping the payload

Solutions like graphql-crunch help dedupe the data but only happen after we've already called the resolvers, and so have to spend its own CPU time running the dedup process.

Ideally we could lean into the GraphQL __typename + id convention for identities and only a) invoke resolvers once, and b) produce a payload that is essentially the GraphQL crunch output but directly as we go, instead of having to crunch after the fact.

@stephenh
Copy link
Collaborator Author

Closing as this isn't really related to Joist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant