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

Resolve empty union objects within Sum schema derivation & cleanups #2121

Merged
merged 5 commits into from
Feb 19, 2024

Conversation

kyri-petrou
Copy link
Collaborator

The main optimization in this PR is that we avoid matching on PureStep(EnumValue(v)) for all steps by delegating this responsibility to the derived Sum schema.

Other cleanups & minor optimizations that I came across while working on this PR:

  1. Moved handling of empty union objects into a common Scala 2 & 3 object to avoid code duplication
  2. Added the __DeprecatedArgs.include since we've been using __DeprecatedArgs(Some(true)) quite a lot
  3. Moved StreamStep reduction into separate method so that the pattern matching doesn't contain any reduction logic
  4. Improved performance of Field#allFieldsUniqueNameAndCondition by avoiding creation of the HashSet when there's only 1 queried field in the object

With these changes, we see ~10% improvement in execution of simple queries (where only the top-level field is effectful) and ~5% for cases that fields contain ZQueries

Comment on lines +7 to +13
// NOTE: This object extends AbstractFunction1 to maintain binary compatibility for Scala 2.13.
// TODO: Remove inheritance in the next major version
object __DeprecatedArgs extends AbstractFunction1[Option[Boolean], __DeprecatedArgs] {
val include: __DeprecatedArgs = __DeprecatedArgs(Some(true))

def apply(v: Option[Boolean] = None): __DeprecatedArgs = new __DeprecatedArgs(v)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fairly annoying we have to extend AbstractFunction1 to make MiMA happy with Scala 2.13. We can remove this for 2.6.0

@@ -1,10 +1,11 @@
package caliban.schema

import caliban.ResponseValue.ObjectValue
Copy link
Owner

Choose a reason for hiding this comment

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

Are imports right?

@@ -1,7 +1,8 @@
package caliban.schema

import caliban.CalibanError.ExecutionError
import caliban.Value.NullValue
import caliban.ResponseValue.ObjectValue
Copy link
Owner

Choose a reason for hiding this comment

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

Unused imports ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed. By the way shall we add a linter to check for unused imports and run it during CI only? It's pretty easy to miss them unfortunately

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah that'd be nice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok I'll add it in a separate PR 👍

@kyri-petrou kyri-petrou merged commit 26373cf into series/2.x Feb 19, 2024
10 checks passed
@kyri-petrou kyri-petrou deleted the optimize-step-reduction-pattern-matching branch February 19, 2024 00:45
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.

2 participants