-
Couldn't load subscription status.
- Fork 1.1k
Avoid allocating a type resolve env if the type is already an object type #2980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid allocating a type resolve env if the type is already an object type #2980
Conversation
| try { | ||
| return asyncHandleException(dataFetcherExceptionHandler, handlerParameters, executionContext); | ||
| return asyncHandleException(dataFetcherExceptionHandler, handlerParameters); | ||
| } catch (Exception handlerException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy scout change - the executionContext was never used
| .exception(handlerException) | ||
| .build(); | ||
| return asyncHandleException(new SimpleDataFetcherExceptionHandler(), handlerParameters, executionContext); | ||
| return asyncHandleException(new SimpleDataFetcherExceptionHandler(), handlerParameters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy scout change - the executionContext was never used
| } | ||
| | ||
| private <T> CompletableFuture<T> asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters, ExecutionContext executionContext) { | ||
| private <T> CompletableFuture<T> asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy scout change - the executionContext was never used
| Object serialized; | ||
| try { | ||
| serialized = enumType.serialize(result); | ||
| serialized = enumType.serialize(result, executionContext.getGraphQLContext(), executionContext.getLocale()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy scout change - the deprecated method should not have been using this mechanism
| .objectType(resolvedObjectType) | ||
| .fragments(executionContext.getFragmentsByName()) | ||
| .variables(executionContext.getVariables()) | ||
| .variables(executionContext.getCoercedVariables().toMap()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy scout change - the deprecated method was used
…type - restored protected method
| // we can avoid a method call and type resolver environment allocation if we know it's an object type | ||
| if (fieldType instanceof GraphQLObjectType) { | ||
| return (GraphQLObjectType) fieldType; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can avoid calling the extra method and inside that the resolver type env allocation if we know its an object type upfront
I originally did this inside esolvedType.resolveType() but why even call it with object types. This is faster
| | ||
| /** | ||
| * See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), | ||
| * See (<a href="http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability">...</a>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boy scout change - warning from IDEA
| GraphQLObjectType resolvedType; | ||
| Assert.assertTrue(fieldType instanceof GraphQLInterfaceType || fieldType instanceof GraphQLUnionType, | ||
| () -> "The passed in fieldType MUST be an interface or union type : " + fieldType.getClass().getName()); | ||
| TypeResolutionEnvironment env = buildEnv(executionContext, field, source, executionStepInfo, fieldType, localContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now ONLY take unions and interfaces. Since the object type check is outside now. This class is NOT general purpose and ONLY used above
…type - restored direct env allocation code
| public GraphQLObjectType resolveType(ExecutionContext executionContext, MergedField field, Object source, ExecutionStepInfo executionStepInfo, GraphQLType fieldType, Object localContext) { | ||
| GraphQLObjectType resolvedType; | ||
| Assert.assertTrue(fieldType instanceof GraphQLInterfaceType || fieldType instanceof GraphQLUnionType, | ||
| () -> "The passed in fieldType MUST be an interface or union type : " + fieldType.getClass().getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now only interfaces and unions into this method. The outer code does the object check.
I know its more self contained if perhaps did all three but performance is performance. Not only do we avoid a env object allocation - we avoid a method call as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This will improve the runtime for every object type encountered since the type env allocation (and indeed method call) is not needed