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

[RFC] Cache parsed and validated queries in memory #2170

Closed
wants to merge 1 commit into from

Conversation

mxstbr
Copy link

@mxstbr mxstbr commented Jan 10, 2019

A first RFC to kick off a discussion about caching parsed and validated
queries. This is based on the ideas from graphql/graphql-js#158

GraphQL APIs often get the same queries with different variables over
and over. Even though the query string doesn't change, Apollo server
parses and validates it on every request.

Instead, we can cache the resulting AST and skip the parsing and
validation step on further requests with the same query. While I don't
think this will provide an order of magnitude of a speedup, it seems
like it would avoid unnecessary work, could help in performance
sensitive scenarios and doesn't add much complexity.

This PR implements this in a very crude way to kick off a discussion
about including this in Apollo Server.

TODO:

  • Decide on scope (external caches? persisted queries?)
  • Add an option to disable/enable/configure
  • Make it a LRU cache to avoid balooning memory?
  • TBD
  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • 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

A first RFC to kick off a discussion about caching parsed and validated
queries. This is based on the ideas from [graphql/graphql-js#158](graphql/graphql-js#158)

GraphQL APIs often get the same queries with different variables over
and over. Even though the query string doesn't change, Apollo server
parses and validates it on every request.

Instead, we can cache the resulting AST and skip the parsing and
validation step on further requests with the same query. While I don't
think this will provide an order of magnitude of a speedup, it seems
like it would avoid unnecessary work, could help in performance
sensitive scenarios and doesn't add much complexity.

This commit implements this in a very crude way to kick off a discussion
about including this in Apollo Server.
@martijnwalraven
Copy link
Contributor

@mxstbr Thanks for looking into this! But there is actually an existing PR for this in flight already: #2111

@mxstbr
Copy link
Author

mxstbr commented Jan 10, 2019

Nevermind I'm a dummy! Will follow #2111!

@mxstbr mxstbr closed this Jan 10, 2019
@mxstbr mxstbr deleted the query-document-caching branch January 10, 2019 08:01
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants