graphql-java: DataFetchingFieldSelectionSetImpl.computeValuesLazily() is slow

I recently captured a few flame graphs of my application, and notice that DataFetchingFieldSelectionSetImpl.computeValuesLazily() shows up in 25% of the flame graphs.

  • I’m wondering if it is expected that this take up so many CPU cycles?
  • Why does it take so long to computeValuesLazily ? When I remove calling getSelectionSet() in my application code the application uses 40% as much CPU, so It seems like without this the graphql-java is able to understand the query and execute the datafetchers.
  • if there are optimizations I can make to improve the performance?

details: My app is a DGS/spring-graphql/Springboot app

in my application code in the DataFetcher for a top level Query field I am calling: DataFetchingEnvironment.getSelectionSet().getFields("subField"); so that I can then get an argument to subfield so that I can use it to make a call to the backend to get the right data.

Also my schema is kind of large, which may be why

libraries:

javaVersion 21.0.3.0.101
spring-boot 3.3.4
spring graphql-1.3.2
graphql-java-22.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Is there anyway for me to cache the query/schema that gets parsed in DataFetchingFieldSelectionSetImpl?

No because DataFetchingFieldSelectionSet contains live per query information - eg argument values say

    private final ImmutableMap<String, NormalizedInputValue> normalizedArguments;
    private final LinkedHashMap<String, Object> resolvedArguments;

It cant be cross request cached.