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 creation when the SelectionSet doesn't contain fragments #2280

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

kyri-petrou
Copy link
Collaborator

During Field creation, we use a LinkedHashMap in order to deduplicate and combine fields depending on the field aliased name and the condition. I have no idea why this never occurred to me before, but this is only necessary when the SelectionSet contains fragments. In cases that it doesn't contain any fragments, we can simply just add just the Fields in a ListBuffer which is much cheaper.

Based on the newly added benchmarks, we see a 50-90% improvement in this post-validation phase.

PS: This phase was quite fast already, so I don't think we'll see much of this improvement reflected to the total execution time, but it's still nice not having to waste CPU cycles especially for services deployed in a k8s cluster

series/2.x:

[info] Benchmark                                         Mode  Cnt        Score       Error  Units
[info] ValidationBenchmark.postValidationDeep           thrpt   10  1919896.457 ± 16097.774  ops/s
[info] ValidationBenchmark.postValidationIntrospection  thrpt   10   227253.553 ±  1415.620  ops/s
[info] ValidationBenchmark.postValidationMultifield     thrpt   10  2223595.997 ± 12263.328  ops/s
[info] ValidationBenchmark.postValidationSimple         thrpt   10  5760613.925 ± 88803.131  ops/s

PR:

[info] Benchmark                                         Mode  Cnt        Score        Error  Units
[info] ValidationBenchmark.postValidationDeep           thrpt   10  3570988.986 ± 251199.323  ops/s
[info] ValidationBenchmark.postValidationIntrospection  thrpt   10   332137.620 ±  10887.654  ops/s
[info] ValidationBenchmark.postValidationMultifield     thrpt   10  4128116.557 ±   8987.987  ops/s
[info] ValidationBenchmark.postValidationSimple         thrpt   10  9185483.477 ±  80255.025  ops/s

@ghostdogpr ghostdogpr merged commit 1cf09f8 into series/2.x Jun 17, 2024
10 checks passed
@ghostdogpr ghostdogpr deleted the optimize-field-creation branch June 17, 2024 00:22
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