Utilize ZIO / ZQuery eager constructors and accessors wherever possible #2297
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: PR is going to fail because the zio-query dependency is a Snapshot version. I'll update this PR once I realise zio-query v0.7.2
This PR better utilizes ZIO and ZQuery eager methods and accessors in the following ways:
Exit.succeed
wherever we don't need to capture side-effects or recurse in a methodif
statements to avoid lazy evaluation and extra allocationsExit
from aZQuery
, and evaluate it as a pure value if it's possibleI'd like to elaborate a bit more on (3). In the GQL applications I have at $WORK, we often define our types like this:
Depending on some logic that handles query composition, in some cases we already know the
name
andage
. So we can do this:In such cases, Caliban can treat these query fields as pure values and reduce the field as if the type didn't contain any queries.
I run some benchmarks comparing the performance of using
ZQuery.succeed
vsZQuery.succeedNow
on some of the fields onMultiFieldEntity
:Even if we were not able to fully reduce the object (since it still contains 1 field that uses
ZQuery.succeed
) we managed to double our throughput by extracting the values from the fields that were eagerly constructed.