Skip to content

Performance improvements to checkTypeRegistry (isSubTypeOf) - #4528

Merged
bbakerman merged 2 commits into
graphql-java:masterfrom
xuorig:perf/allocation-free-is-subtype-of
Nov 3, 2026
Merged

bbakerman merged 2 commits into
graphql-java:masterfrom
xuorig:perf/allocation-free-is-subtype-of

Conversation

@xuorig

@xuorig xuorig commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

TypeDefinitionRegistry.isSubTypeOf is called for every field an implementing type shares with each of its interfaces, as part of SchemaTypeChecker.checkTypeRegistry, which both SchemaGenerator and FastSchemaGenerator run. On large schemas it is a very slow procedure.

Each call allocated two TypeInfos (each with an ArrayDeque), plus another two per level of NonNull/List unwrapping. In the abstract-type case it looked up each type definition twice, once in isInterfaceOrUnion/isObjectTypeOrInterface and again in isPossibleType. It also used streams in implementsInterface and isUnionMember which similar to recent improvements to graphql-java, are changed into regular loops.

Bug fix

While working on this I also found a potential bug? The "equivalent type is a valid subtype" shortcut used TypeInfo.equals, which only compares the outermost wrapper and the innermost type name. So it returned true for:

[String]   <: [String!]
[[String]] <: [String]
[String]   <: [[String]]

As a result, the SDL type checker didn't report InterfaceFieldRedefinitionError for e.g. interface I { f: [String!] } / type T implements I { f: [String] }. With schema validation on, SchemaValidator still rejected these later. With validation off (withValidation(false), which could happen with FastSchemaGenerator), they were accepted.

The name comparison now happens only once both sides are unwrapped to a named type. The recursion already handled the wrappers. TypeInfo.equals/hashCode are also fixed to compare the full wrapper chain, for anyone relying on them.

Marc-Andre Giroux added 2 commits November 1, 2026 11:49
…alent

The equivalence shortcut relied on TypeInfo.equals, which only compared
the outermost wrapper and the innermost name, so [String] was a subtype
of [String!] and [[String]] of [String]. Compare names only once both
sides are unwrapped, and fix TypeInfo.equals/hashCode to compare the
full wrapper chain.
@xuorig
xuorig force-pushed the perf/allocation-free-is-subtype-of branch from 8bafa38 to 912ed91 Compare November 2, 2026 15:22
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6178 (+1 🟢) 6122 (+1 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 21 6178 (+1 🟢) 6122 (+1 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 25 6178 (+1 🟢) 6122 (+1 🟢) 0 (±0) 0 (±0) 56 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 18566 (+3 🟢) 18398 (+3 🟢) 0 (±0) 0 (±0) 168 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30320 3082 90.8% ±0.0%
Branches 8954 1506 85.6% ±0.0%
Methods 8094 1188 87.2% ±0.0%

Changed Class Coverage (2 classes)

Class Line Branch Method
g.s.i.TypeDefinitionRegistry +0.2% 🟢 +1.8% 🟢 ±0.0%
g.s.i.TypeInfo -0.7% 🔴 -0.2% 🔴 +0.7% 🟢
TypeInfo — method details
Method Line Branch
sameDecoration new 87.5% 83.3%

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-02 15:32:35 UTC

@bbakerman bbakerman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok - tests pass

@bbakerman
bbakerman merged commit a44e51d into graphql-java:master Nov 3, 2026
7 of 9 checks passed

@bbakerman bbakerman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants