Improve auto-configuration sorting performance - #51867
Merged
philwebb merged 2 commits intoSep 28, 2026
Merged
Conversation
Update `AutoConfigurationSorter` to improve performance by building reverse `@AutoConfigureBefore` relationships while the auto-configuration graph is created and using stable sort ranks during traversal. See spring-projectsgh-51867 Signed-off-by: aalsanie <ahmad.alsanie@hotmail.com>
philwebb
force-pushed
the
perf/auto-configuration-sorter
branch
from
September 28, 2026 22:36
eaf1e10 to
875efab
Compare
Member
|
Thanks very much @aalsanie! |
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.
AutoConfigurationSortercurrently performs repeated linear scans while resolving ordering relationships.getClassesRequestedAfter()scans all known auto configrations to reverse@AutoConfigureBefore, while annotation traversal repeatedly usesindexOf(),contains(), and remove from the front ofArrayList.Related to #51643, which identified the same scaling problem. This change takes a different approach by building reverse
@AutoConfigureBeforerelationships while the auto-configuration graph is created and using stable sort ranks during traversal.Here, I remove those repeated scans while keeping the existing ordering behavior.
Performance
Measured against
main.JMH configuration: 3 forks, 5 × 1-second warmup iterations, and 8 × 1-second measurement iterations.
mainNONE, 1024MIXED, 1024FAN_IN, 1024FAN_INscaling:mainI also tested the change in a spring boot application with 1024 ordered synthetic auto-configurations. I ran 20 fresh JVM starts for each version, alternating between baseline and optimized runs.
mainMedian context startup improved by 50.806 ms (2.97%). Here is the benchmark sources with reproduction commands:
https://github.com/aalsanie/spring-boot-auto-configuration-sorter-benchmarks
Verification
Additional tests cover stable ordering for mixed before/after/order relationships, reversed input, duplicate input names, transitively discovered classes, and exact cycle reporting.