Description
Library Version
graphql-kotlin-spring-server:6.2.5
Describe the bug
I have encountered performance problems with a large number of requests. After deeper analysis, I found out that a query with input fields is much slower than a query without. Having many objects with input fields increases the problem even more.
Steps to reproduce
class ExampleQuery: Query {
fun example(): List<ExampleType> = (1..20).map { ExampleType() }
}
data class ExampleType(
val number: Int = Random.nextInt()
) {
fun addition(a: Int, b: Int) = a + b
}
Now we can execute two different queries
Query A | Query B |
---|---|
query QueryA { |
query QueryB { |
When timing the requests to the endpoint, we can measure the following execution times:
Query | Min | Max | Mean | Std |
---|---|---|---|---|
A | 1.4ms | 37.8ms | 5.0ms | 4.4ms |
B | 13.7ms | 271.9ms | 36.4ms | 36.2ms |
When including input fields, the execution time is 7-10 times worse. In fact, this means that we have to run up to 10 times more instances to handle the same amount of load.
I've created a small repo to reproduce my results: https://github.com/dhartung/graphql-kotlin-demo
Expected behavior
Adding or removing input types to the query should make almost no difference to the execution time.