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 Field#allFieldsUniqueNameAndCondition #2368

Merged
merged 3 commits into from
Aug 24, 2024

Conversation

kyri-petrou
Copy link
Collaborator

This method exists in the very hot path of execution, so even micro-optimizations to it are quite nice.

Basically this PR does the following:

  1. Avoids initializing the lazy val when we can check if the conditions are unique without iterating through the fields
  2. Removes the unique check on the aliasedName, which also removes the need for allocating a HashSet. It just occurred to me that we if the conditions are all the same, then the names are guaranteed to be unique because otherwise we would have deduplicated them when we create the Field

private[caliban] def allFieldsUniqueNameAndCondition: Boolean =
fields.isEmpty || fields.tail.isEmpty || allConditionsUniqueLzy

private lazy val allConditionsUniqueLzy: Boolean = {
Copy link
Owner

Choose a reason for hiding this comment

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

Lzy -> Lazy?

@kyri-petrou kyri-petrou merged commit 9929056 into series/2.x Aug 24, 2024
10 checks passed
@kyri-petrou kyri-petrou deleted the optimize-allfields-unique-name branch August 24, 2024 10: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