-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Minor performance fixes #3236
Minor performance fixes #3236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,15 @@ | ||
package graphql.execution; | ||
|
||
import graphql.Internal; | ||
import graphql.introspection.Introspection; | ||
import graphql.language.Argument; | ||
import graphql.schema.GraphQLCodeRegistry; | ||
import graphql.schema.GraphQLFieldDefinition; | ||
import graphql.schema.GraphQLList; | ||
import graphql.schema.GraphQLObjectType; | ||
import graphql.schema.GraphQLOutputType; | ||
import graphql.util.FpKit; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
@Internal | ||
public class ExecutionStepInfoFactory { | ||
|
||
public ExecutionStepInfo newExecutionStepInfoForSubField(ExecutionContext executionContext, MergedField mergedField, ExecutionStepInfo parentInfo) { | ||
GraphQLObjectType parentType = (GraphQLObjectType) parentInfo.getUnwrappedNonNullType(); | ||
GraphQLFieldDefinition fieldDefinition = Introspection.getFieldDef(executionContext.getGraphQLSchema(), parentType, mergedField.getName()); | ||
GraphQLOutputType fieldType = fieldDefinition.getType(); | ||
List<Argument> fieldArgs = mergedField.getArguments(); | ||
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry(); | ||
Supplier<Map<String, Object>> argumentValuesSupplier = () -> ValuesResolver.getArgumentValues(codeRegistry, | ||
fieldDefinition.getArguments(), | ||
fieldArgs, | ||
executionContext.getCoercedVariables(), | ||
executionContext.getGraphQLContext(), | ||
executionContext.getLocale()); | ||
Supplier<Map<String, Object>> argumentValues = FpKit.intraThreadMemoize(argumentValuesSupplier); | ||
|
||
ResultPath newPath = parentInfo.getPath().segment(mergedField.getResultKey()); | ||
|
||
return parentInfo.transform(builder -> builder | ||
.parentInfo(parentInfo) | ||
.type(fieldType) | ||
.fieldDefinition(fieldDefinition) | ||
.fieldContainer(parentType) | ||
.field(mergedField) | ||
.path(newPath) | ||
.arguments(argumentValues)); | ||
} | ||
|
||
public ExecutionStepInfo newExecutionStepInfoForListElement(ExecutionStepInfo executionInfo, int index) { | ||
public ExecutionStepInfo newExecutionStepInfoForListElement(ExecutionStepInfo executionInfo, ResultPath indexedPath) { | ||
GraphQLList fieldType = (GraphQLList) executionInfo.getUnwrappedNonNullType(); | ||
GraphQLOutputType typeInList = (GraphQLOutputType) fieldType.getWrappedType(); | ||
ResultPath indexedPath = executionInfo.getPath().segment(index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to my memory profiler, this is dropping from 3-4% of total heap to just 1-2% (as expected) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to explain to others - the indexedPath was allocated out side this method and then reallocated again here. This double allocation has been removed |
||
return executionInfo.transform(builder -> builder | ||
.parentInfo(executionInfo) | ||
.type(typeInList) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,6 @@ public class ExecutionStrategyParameters { | |
private final NonNullableFieldValidator nonNullableFieldValidator; | ||
private final ResultPath path; | ||
private final MergedField currentField; | ||
private final int listSize; | ||
private final int currentListIndex; | ||
private final ExecutionStrategyParameters parent; | ||
|
||
private ExecutionStrategyParameters(ExecutionStepInfo executionStepInfo, | ||
|
@@ -30,8 +28,6 @@ private ExecutionStrategyParameters(ExecutionStepInfo executionStepInfo, | |
NonNullableFieldValidator nonNullableFieldValidator, | ||
ResultPath path, | ||
MergedField currentField, | ||
int listSize, | ||
int currentListIndex, | ||
ExecutionStrategyParameters parent) { | ||
|
||
this.executionStepInfo = assertNotNull(executionStepInfo, () -> "executionStepInfo is null"); | ||
|
@@ -41,8 +37,6 @@ private ExecutionStrategyParameters(ExecutionStepInfo executionStepInfo, | |
this.nonNullableFieldValidator = nonNullableFieldValidator; | ||
this.path = path; | ||
this.currentField = currentField; | ||
this.listSize = listSize; | ||
this.currentListIndex = currentListIndex; | ||
this.parent = parent; | ||
} | ||
|
||
|
@@ -70,14 +64,6 @@ public Object getLocalContext() { | |
return localContext; | ||
} | ||
|
||
public int getListSize() { | ||
return listSize; | ||
} | ||
|
||
public int getCurrentListIndex() { | ||
return currentListIndex; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are not used anywhere and are informational |
||
public ExecutionStrategyParameters getParent() { | ||
return parent; | ||
} | ||
|
@@ -119,8 +105,6 @@ public static class Builder { | |
NonNullableFieldValidator nonNullableFieldValidator; | ||
ResultPath path = ResultPath.rootPath(); | ||
MergedField currentField; | ||
int listSize; | ||
int currentListIndex; | ||
ExecutionStrategyParameters parent; | ||
|
||
/** | ||
|
@@ -141,8 +125,6 @@ private Builder(ExecutionStrategyParameters oldParameters) { | |
this.currentField = oldParameters.currentField; | ||
this.path = oldParameters.path; | ||
this.parent = oldParameters.parent; | ||
this.listSize = oldParameters.listSize; | ||
this.currentListIndex = oldParameters.currentListIndex; | ||
} | ||
|
||
public Builder executionStepInfo(ExecutionStepInfo executionStepInfo) { | ||
|
@@ -185,24 +167,14 @@ public Builder path(ResultPath path) { | |
return this; | ||
} | ||
|
||
public Builder listSize(int listSize) { | ||
this.listSize = listSize; | ||
return this; | ||
} | ||
|
||
public Builder currentListIndex(int currentListIndex) { | ||
this.currentListIndex = currentListIndex; | ||
return this; | ||
} | ||
|
||
public Builder parent(ExecutionStrategyParameters parent) { | ||
this.parent = parent; | ||
return this; | ||
} | ||
|
||
|
||
public ExecutionStrategyParameters build() { | ||
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, listSize, currentListIndex, parent); | ||
return new ExecutionStrategyParameters(executionStepInfo, source, localContext, fields, nonNullableFieldValidator, path, currentField, parent); | ||
} | ||
} | ||
} |
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.
just checked - code was never used