graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Parallel get extended field definitions

Open coolbeevip opened this issue 3 years ago • 0 comments

I want to suggest an idea and checked that ...

  • [X] ... to my best knowledge, my idea wouldn't break something for other users
  • [X] ... the documentation does not mention anything about my idea
  • [X] ... there are no open or closed issues that are related to my idea

Description

I have a big project that contains the too many graphqls, SchemaClassScanner takes 5 minutes to execute

Use Cases

I added some logs in method scanForClasses,This is my log output

SchemaClassScanner.kt:84 - Schema scan discover Query field 5611, time elapsed 83960ms
SchemaClassScanner.kt:85 - Schema scan discover Mutation...
SchemaClassScanner.kt:88 - Schema scan discover Mutation field 16461, time elapsed 218258ms
SchemaClassScanner.kt:89 - Schema scan discover Subscription...
SchemaClassScanner.kt:92 - Schema scan discover Subscription field 0, time elapsed 0ms
SchemaClassScanner.kt:94 - Schema scan Queue
SchemaClassScanner.kt:108 - Schema scan Queue time elapsed 4470ms

I tried to solve this problem using parallel stream

  • modify the line to type.getExtendedFieldDefinitions(extensionDefinitions).parallelStream().forEach { field ->

https://github.com/graphql-java-kickstart/graphql-java-tools/blob/b5d41b145a6cfbdc07b03144499a6387f743adab/src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt#L268

  • modify the line to private val queue = Collections.synchronizedSet(linkedSetOf<QueueItem>())

https://github.com/graphql-java-kickstart/graphql-java-tools/blob/b5d41b145a6cfbdc07b03144499a6387f743adab/src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt#L46

The performance has been improved after the modification

Schema scan discover Query...
Schema scan discover Query field 5611, time elapsed 27539ms
SchemaClassScanner.kt:86 - Schema scan discover Mutation...
Schema scan discover Mutation field 16461, time elapsed 69114ms
Schema scan discover Subscription...
Schema scan discover Subscription field 0, time elapsed 0ms
SchemaClassScanner.kt:109 - Schema scan Queue time elapsed 4403ms

But, I failed to startup, and I found a lot of the following information in the log

Schema type was defined but can never be accessed, and can be safely deleted: XXX
...
Resolver was provided but no methods on it were used in data fetchers and can be safely deleted: XXX
...

I just want to improve the startup speed, what do you any suggestions?

coolbeevip avatar Jun 05 '21 08:06 coolbeevip