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

Optimize execution of pure and single-field object queries #2338

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

kyri-petrou
Copy link
Collaborator

This PR optimizes the execution of the following:

  1. Queries which query a single field from objects, and that field is effectful
  2. Queries that do not contain any effectful fields. While this might seem like a very specific / non-realistic optimization, it is quite relevant for Loom-based frameworks where we don't need to use effects for async/blocking tasks

stepReducer.reduceStep(plan, request.field, Map.empty, Nil) match {
case PureStep(resp) => Exit.succeed(GraphQLResponse(resp, Nil))
case reducedStep => makeCache.flatMap(runQuery(reducedStep, _))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we still need to suspend this? Returning an Exit means we lose referential transparency if it's now getting strictly evaluated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technicaly, you're right, this is a bit of an interesting because we execute this method on each request, and it's not really a user-facing method (even if it's public). So it doesn't need to be referentially transparent. But since it does return a ZIO, I think we should make it referentially transparent to avoid any potential issues in the future

case None => Exit.unit
case Some(w) => w
else
ZIO.suspendSucceed {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added this here in order to align with https://github.com/ghostdogpr/caliban/pull/2338/files#r1673288713. We don't need this method to be referentially transparent because it's executed on each request, but better to have it referentially transparent for consistency

@kyri-petrou kyri-petrou merged commit f78be97 into series/2.x Jul 11, 2024
10 checks passed
@kyri-petrou kyri-petrou deleted the optimize-single-field-queries branch July 11, 2024 12:17
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.

3 participants