Avoid redundant type inspection and contribution during repository AOT processing - #3519
Open
snuderl wants to merge 1 commit into
Open
Avoid redundant type inspection and contribution during repository AOT processing#3519snuderl wants to merge 1 commit into
snuderl wants to merge 1 commit into
Conversation
…T processing. Repository AOT processing walked the same domain type graph once per repository and once per contributed type. `DefaultAotRepositoryContext.discoverTypes()` scanned the configured base packages for types carrying the store's identifying annotations and inspected all of them for every repository, and `TypeContributor.contribute(…)` handed each resolved type to `BindingReflectionHintsRegistrar` individually, which starts with a fresh `seen` set per call and therefore re-traverses shared types once per resolved type. `TypeCollector.ReachableTypes` additionally used a per-root inspection cache, re-inspecting types reachable from more than one root. Base package scan results are now cached across the repository contexts created by a `RepositoryRegistrationAotProcessor`, reachable type inspection shares one inspection cache across all roots of a `ReachableTypes` instance, and resolved types are contributed in a single `BindingReflectionHintsRegistrar` pass while skipping types already contributed to the same `RuntimeHints`. The generated `reachability-metadata.json` is unchanged. For an application with 17 Mongo repositories over a Jackson-annotated protobuf domain model, `SpringApplicationAotProcessor` drops from 60s to 12s; for a synthetic application with 32 repositories, from 33.6s to 4.5s. Signed-off-by: Blaz Snuderl <blaz.snuderl@opensea.io> Co-Authored-By: Blaz Snuderl <blaz.snuderl@opensea.io>
mp911de
force-pushed
the
main
branch
3 times, most recently
from
August 4, 2026 14:39
bde036c to
adb1c6d
Compare
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.
Closes #3518.
Repository AOT processing walks the same domain type graph repeatedly, which makes
SpringApplicationAotProcessorscale poorly with the number of repositories and the size of the domain model:DefaultAotRepositoryContext.discoverTypes()scans the configured base packages for types carrying the store's identifying annotations and inspects all of them — for every repository.TypeContributor.contribute(…)hands each resolved type toBindingReflectionHintsRegistrarindividually. The registrar starts with a freshseenset per call, so shared types are re-traversed once per resolved type.TypeCollector.ReachableTypesuses a per-root inspection cache, re-inspecting types reachable from more than one root.This PR addresses all three:
RepositoryRegistrationAotProcessor.ReachableTypesinstance.BindingReflectionHintsRegistrarpass, skipping types already contributed to the sameRuntimeHints.The generated
reachability-metadata.jsonis unchanged. For a real application with 17 Mongo repositories over a Jackson-annotated protobuf domain model,SpringApplicationAotProcessordrops from 60s to 12s; for a synthetic application with 32 repositories, from 33.6s to 4.5s.A standalone reproducer with scaling measurements is available at https://github.com/snuderl/spring-data-aot-repro.