Added a read only copy of a type registry for performance reasons by bbakerman · Pull Request #4021 · graphql-java/graphql-java · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions src/main/java/graphql/schema/idl/ImmutableTypeDefinitionRegistry.java
10 changes: 6 additions & 4 deletions src/main/java/graphql/schema/idl/SchemaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ public GraphQLSchema makeExecutableSchema(Options options, TypeDefinitionRegistr

schemaGeneratorHelper.addDirectivesIncludedByDefault(typeRegistryCopy);

List<GraphQLError> errors = typeChecker.checkTypeRegistry(typeRegistryCopy, wiring);
// by making it read only all the traversal and checks run faster
ImmutableTypeDefinitionRegistry fasterImmutableRegistry = typeRegistryCopy.readOnly();
List<GraphQLError> errors = typeChecker.checkTypeRegistry(fasterImmutableRegistry, wiring);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the performance gains will be made

if (!errors.isEmpty()) {
throw new SchemaProblem(errors);
}

Map<String, OperationTypeDefinition> operationTypeDefinitions = SchemaExtensionsChecker.gatherOperationDefs(typeRegistry);
Map<String, OperationTypeDefinition> operationTypeDefinitions = SchemaExtensionsChecker.gatherOperationDefs(fasterImmutableRegistry);

return makeExecutableSchemaImpl(typeRegistryCopy, wiring, operationTypeDefinitions, options);
return makeExecutableSchemaImpl(fasterImmutableRegistry, wiring, operationTypeDefinitions, options);
}

private GraphQLSchema makeExecutableSchemaImpl(TypeDefinitionRegistry typeRegistry,
private GraphQLSchema makeExecutableSchemaImpl(ImmutableTypeDefinitionRegistry typeRegistry,
RuntimeWiring wiring,
Map<String, OperationTypeDefinition> operationTypeDefinitions,
Options options) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class SchemaGeneratorHelper {
* it gives us helper functions
*/
static class BuildContext {
private final TypeDefinitionRegistry typeRegistry;
private final ImmutableTypeDefinitionRegistry typeRegistry;
private final RuntimeWiring wiring;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this use the type just to be more explicit but I didnt change it every where it gets used

private final Deque<String> typeStack = new ArrayDeque<>();

Expand All @@ -123,7 +123,7 @@ static class BuildContext {
public final SchemaGenerator.Options options;
public boolean directiveWiringRequired;

BuildContext(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring, Map<String, OperationTypeDefinition> operationTypeDefinitions, SchemaGenerator.Options options) {
BuildContext(ImmutableTypeDefinitionRegistry typeRegistry, RuntimeWiring wiring, Map<String, OperationTypeDefinition> operationTypeDefinitions, SchemaGenerator.Options options) {
this.typeRegistry = typeRegistry;
this.wiring = wiring;
this.codeRegistry = GraphQLCodeRegistry.newCodeRegistry(wiring.getCodeRegistry());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/schema/idl/SchemaTypeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
@Internal
public class SchemaTypeChecker {

public List<GraphQLError> checkTypeRegistry(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem {
public List<GraphQLError> checkTypeRegistry(ImmutableTypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this use the type just to be more explicit but I didnt change it every where it gets used

List<GraphQLError> errors = new ArrayList<>();
checkForMissingTypes(errors, typeRegistry);

Expand Down
76 changes: 63 additions & 13 deletions src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
Loading