Skip to content

graphql: added caching for validation phase #3188

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

Closed
wants to merge 1 commit into from

Conversation

dotansimha
Copy link
Contributor

@dotansimha dotansimha commented Jan 25, 2022

Closes #3077

TODO

  • Add global cache for validation results
  • Make sure cache does not cause false positives due to hash calculation

Overview of this PR

Since validate is static (give a query and a schema it will always produce the same result), we can cache it to avoid running it again and again if a given query hash is the same.

Benchmarks

Measured on M1 machine, in --release mode.

Phase Without Cache With HashMap
validate ~1.44ms <=1µs
GraphQL query used for testing
{
  purposes(first: 100, subgraphError: allow) {
    id
    sender {
      id
      ...SenderFields
    }
    ...PurposeFields
  }
}

fragment PurposeFields on Purpose {
  purpose
  createdAt
  transactionHash
}

fragment SenderFields on Sender {
  address
  createdAt
  purposeCount
}

It seems like parse takes ~60µs so we don't have to do any significant optimizations at the moment.

@dotansimha dotansimha requested a review from lutter January 25, 2022 15:39
@dotansimha dotansimha marked this pull request as draft January 25, 2022 16:41
@dotansimha
Copy link
Contributor Author

After a discussion with @lutter , we can drop caching validations at the moment, since it's not adding a real overhead (~1ms).

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

Successfully merging this pull request may close these issues.

GraphQL parse/validation caching
1 participant