Skip to content

Queries that include input fields are executed slowly #1570

Open
@dhartung

Description

@dhartung

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 {
example {
one: number
two: number
three: number
}
}
query QueryB {
example {
one: addition(a: 500, b: 600)
two: addition(a: 400, b: 700)
three: addition(a: 300, b: 900)
}
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueA good place to start as a new contributormodule: generatorIssue affects the schema generator and federation codetype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions