-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache result of RepositoryInformationSupport.getQueryMethods()
#3066
Comments
Thank you @dodgex for raising the issue. Let me take this to the team. |
Thanks for bringing this up. I've introduced a cache for the query methods and the information calculated in |
@odrotbohm I gave your changes a quick try. The application started as "quickly" as with my hacky solution, and as far as I tested everything worked! And as expected your implementation is a bit cleaner than mine. ;) I found that your polishing commit got a typo in Thanks for the quick fix. |
Great feedback, thanks! We tend to use I'll apply those fixes and backport the changes. |
We now calculate information about query methods in RepositoryInformationSupport lazily and keep it around to avoid repeated calculations that involve traversals over declared method and Stream allocations. Fixes GH-3066.
We now calculate information about query methods in RepositoryInformationSupport lazily and keep it around to avoid repeated calculations that involve traversals over declared method and Stream allocations. Fixes GH-3066.
We now calculate information about query methods in RepositoryInformationSupport lazily and keep it around to avoid repeated calculations that involve traversals over declared method and Stream allocations. Fixes GH-3066.
This should be all in place now. |
RepositoryInformationSupport.getQueryMethods()
Hey there,
I work on a project that has over 250 JPA Repositories (distributed over 3 databases / persistence unites). The startup time in development and also production takes a big hit due to this fact.
While searching for the reason for the long startup times, i came across the
getQueryMethods()
inRepositoryInformationSupport
(in 2.7.x it was inDefaultRepositoryInformation
) and that it scans the repository interface for all methods and builds a set of qualified query methods.This method is called in a lot of places, and multiple times during startup. and some places get all methods, only to search for one single after this...
e.g
RepositoryInformationSupport.java#L126
or RepositoryInformation.java#L85-L91
While in most cases, this should not be a to big problem, for bigger projects this could have huge impact. and even smaller projects could start even faster.
For testing purposes, I created a copy of the
org.springframework.data.repository.core.DefaultRepositoryInformation
in my development environment and changed thegetQueryMethods
to keep the result of the first invocation and do not scan the class again.For 3.2.3 my implementation looks like this:
With this small change, my project startup time shrinks from ~120 seconds to ~40-45 seconds using Spring Boot 3.2.3. That is an improvement of about 60%.
While I do not have a deeper knowledge of what impact/sideeffect it could have to only scan the repository interface once, I can say that i already had this change for Spring Boot 2 in place for now over a year (actually i stumbled over my custom
DefaultRepositoryInformation
while upgrading to SB3). For SB3 I havent done too much testing as of now, but at least there where no immediate issues.The text was updated successfully, but these errors were encountered: