-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
Fix fields merging and improve performance #1199
Conversation
field.fields.foreach { field => | ||
if (field.condition.forall(_.contains(typeName))) { | ||
val name = field.alias.getOrElse(field.name) | ||
map.get(name) match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
was never updated 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -871,6 +870,9 @@ object ExecutionSpec extends DefaultRunnableSpec { | |||
| ... on Human { | |||
| height | |||
| } | |||
| ... on Human { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this intentionally to make sure the result has the field only once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the execution code in detail but I think it looks sensible.
The performance optimizations in the validation also make the code easier to read so a real win-win 🤝
@@ -35,7 +36,33 @@ object Field { | |||
rootType: RootType | |||
): Field = { | |||
def loop(selectionSet: List[Selection], fieldType: __Type): Field = { | |||
val fieldList = List.newBuilder[Field] | |||
val fieldList = ArrayBuffer.empty[Field] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we give this a size hint as well? I'd expect that to provide a minor improvement in 99% of cases where people don't duplicate their fields (and really only penalizes us in the pathological case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we don't know the size without going through fragments recursively.
Fields were not properly merged during execution. I moved the merging to the validation phase and added some performance optimizations.
Before:
After: