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

Fix fields merging and improve performance #1199

Merged
merged 2 commits into from
Dec 12, 2021
Merged

Fix fields merging and improve performance #1199

merged 2 commits into from
Dec 12, 2021

Conversation

ghostdogpr
Copy link
Owner

Fields were not properly merged during execution. I moved the merging to the validation phase and added some performance optimizations.

Before:

[info] Benchmark                               Mode  Cnt      Score      Error  Units
[info] GraphQLBenchmarks.fragmentsCaliban     thrpt    5     27.739 ±    2.741  ops/s
[info] GraphQLBenchmarks.fragmentsSangriaNew  thrpt    5     24.269 ±    4.216  ops/s
[info] GraphQLBenchmarks.fragmentsSangriaOld  thrpt    5      0.165 ±    0.011  ops/s
[info] GraphQLBenchmarks.introspectCaliban    thrpt    5   1585.284 ±  183.560  ops/s
[info] GraphQLBenchmarks.introspectSangria    thrpt    5    499.669 ±   19.512  ops/s
[info] GraphQLBenchmarks.simpleCaliban        thrpt    5  24539.809 ± 1188.386  ops/s
[info] GraphQLBenchmarks.simpleSangria        thrpt    5   7551.214 ± 1423.378  ops/s

After:

[info] Benchmark                               Mode  Cnt      Score     Error  Units
[info] GraphQLBenchmarks.fragmentsCaliban     thrpt    5     44.638 ±   1.523  ops/s
[info] GraphQLBenchmarks.fragmentsSangriaNew  thrpt    5     28.994 ±  16.953  ops/s
[info] GraphQLBenchmarks.fragmentsSangriaOld  thrpt    5      0.155 ±   0.039  ops/s
[info] GraphQLBenchmarks.introspectCaliban    thrpt    5   1782.754 ± 309.681  ops/s
[info] GraphQLBenchmarks.introspectSangria    thrpt    5    500.839 ±  15.303  ops/s
[info] GraphQLBenchmarks.simpleCaliban        thrpt    5  26091.734 ± 305.640  ops/s
[info] GraphQLBenchmarks.simpleSangria        thrpt    5   7831.910 ± 139.665  ops/s

@ghostdogpr ghostdogpr requested a review from frekw December 11, 2021 05:38
field.fields.foreach { field =>
if (field.condition.forall(_.contains(typeName))) {
val name = field.alias.getOrElse(field.name)
map.get(name) match {
Copy link
Owner Author

Choose a reason for hiding this comment

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

map was never updated 🤦‍♂️

Copy link
Collaborator

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 {
Copy link
Owner Author

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.

Copy link
Collaborator

@frekw frekw left a 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]
Copy link
Collaborator

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).

Copy link
Owner Author

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.

@ghostdogpr ghostdogpr merged commit 6802417 into master Dec 12, 2021
@ghostdogpr ghostdogpr deleted the early-merge branch December 12, 2021 00:10
Fluxx pushed a commit to Fluxx/caliban that referenced this pull request Jan 24, 2022
Fluxx pushed a commit to Fluxx/caliban that referenced this pull request Jan 27, 2022
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