GeezerVison is showing github.com — Performance issue in `makeSchema` with schemas containing a lot of extensions by xuorig · Pull Request #4020 · graphql-java/graphql-java
Conversation
xuorig
commented
Jun 23, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
For schemas with a large amount of object extensions, makeSchema can allocate a lot of memory due to the immutable nature of TypeRegistry.*extensions().
The main culprit is src/main/java/graphql/schema/idl/ImplementingTypesChecker.java which repeatedly calls objectTypeExtensions and interfaceTypeExtensions. (first commit)
buildObjectType is also an issue. (second commit).
First commit fix on ImplementingTypesChecker should make a lot of sense, but for buildObjectType, I'd love your opinions. I can cache all kinds of extensions on BuildContext (only did object type for now, as that was our issue).
Can also discuss if there should be cheaper getters on TypeRegistry. I welcome your thoughts!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I think this PR is a good work around. However cheaper accessors is the way forward really
Can also discuss if there should be cheaper getters on TypeRegistry. I welcome your thoughts!
yeah the code today is old and crusty
public Map<String, List<ObjectTypeExtensionDefinition>> objectTypeExtensions() {
return new LinkedHashMap<>(objectTypeExtensions);
}
This idea of copying the objects should be replaced by ImmutableXX collections - we have embraced this elsewhere in the graphql code base but not here is seems.
if we had immutables in place then
return buildCtx.getTypeRegistry().objectTypeExtensions().getOrDefault(typeDefinition.getName(), emptyList());
and
return buildCtx.objectTypeExtensions.getOrDefault(typeDefinition.getName(), emptyList());
would be the same cost
|
xuorig reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Ahh I just had a look at the code - its embraced mutability up the wazoo
typeRegistry.merge(otherTypeReg)
Hmmm immutability is now tricky because its relying on mutability when being built (versus being read)
I am wary that we could make this embrace immutability and not break everyone - is the juice worth the squeeze ??
We need some new structure when its passed in as a "read only" world to say SchemaGenerator and so on
Spitballing this could be
ImmutableTypeRegistry locked = typeRegistry.readOnly()
and then key code could be hanged to used here. In some ways this is what you did when you threaded the "copied" lists into the read only places
Hmmmm tricky to fix systemically
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
ok this PR is probably more systemic
#4021
Now the code covered in this PR gets a graphql.schema.idl.ImmutableTypeDefinitionRegistry and hence asking for the values repeatedly give out the same object and not a copy of the maps
|
xuorig reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Closing in favor of #4021
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.