Index schema model lookups during code generation - #962
Merged
Merged
Conversation
iuliiasobolevska
requested review from
asibross,
iparadiso,
jjacobs44,
kilink,
kzwang,
paulbakker and
srinivasankavitha
as code owners
September 21, 2026 22:12
paulbakker
approved these changes
Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Build a document-scoped schema index once and share it across code generation instead of repeatedly scanning the full GraphQL document.
The index preserves document order and the existing lookup semantics while covering:
Existing public constructors and scan-based overloads remain available for source and binary compatibility. Internal generator paths use the shared index.
This also replaces the remaining interface implementation scan in client projection recursion and prevents duplicate subtype entries when an invalid schema repeats an interface, such as
implements Node & Node.Motivation
Large schemas perform many type and extension lookups during generation. Previously, each lookup walked all document definitions, so lookup work grew with both schema size and the number of generated fields and projections.
Index construction is linear in the document size, after which covered lookups are map-backed. This changes the covered work from repeated full-document scans toward one indexing pass plus lookup-result processing.
Expected performance impact
The adversarial review benchmark used a synthetic 1,200-type schema with extensions, mapped scalars, unions, interfaces, enums, inputs, and client projections. Median generation time improved by:
Actual gains will vary with schema shape and enabled generators. This PR does not claim to eliminate every schema scan; residual per-field lookups in
TypeUtilsare intentionally left for a separate optimization.Correctness safeguards
Verification
./gradlew :graphql-dgs-codegen-core:test :graphql-dgs-codegen-core:integTest --no-scan./gradlew :graphql-dgs-codegen-core:lintKotlinMain :graphql-dgs-codegen-core:lintKotlinTest --no-scan