-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Improve performance of AbstractAutowireCapableBeanFactory#predictBeanType #24681
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
Improve performance of AbstractAutowireCapableBeanFactory#predictBeanType #24681
Conversation
If #24756 is merged, this PR needs to adapt as well. Or vice versa, obviously. |
Anyone willing to review? |
I suppose you are trying to optimize singleton creation performance there, that is, many separate beans of distinct types? I was wondering before whether to cache post-processor applicability to individual beans but that would only improve repeated creation attempts for non-singleton beans... |
It's indeed many separate |
Any chance this might be included in the next release, @jhoeller ? (5.3.0 or even better: 5.2.7) |
I think that could also help on #22060 |
I've implemented a different approach: an internal cache for pre-filtered post-processors, used within the To be committed ASAP, I'll simply repurpose this PR for it (I hope you're ok with that approach). |
Obviously, I appreciate a contribution as much as anyone - but I care more about the problem being fixed, so feel free to go on. I'll take a look once you committed it, because I can't really tell from your description if that actually solves the problem (of simply too many iterations on irrelevant post processors) |
Also includes bulk addition in PostProcessorRegistrationDelegate. Closes spring-projectsgh-24681 Closes spring-projectsgh-24756
Hi,
I am currently trying to improve startup time of a medium sized Spring-Boot app that currently takes around 20 seconds to start. While profiling I noticed that the top hotspot is
AbstractAutowireCapableBeanFactory#predictBeanType
as shown in the screenshot below:Additionally you can see
Iterator.hasNext()/next()
which are also in the top of the list. I found out that a reasonable time is spent iterating overBeanPostProcessors
(23 in my case) for every bean, although most of the post-processors are not aSmartInstantiationAwareBeanPostProcessor
at all (only 3 in my case), which are the only post-processors of interest for predicting bean types. Even worse, almost all standard smart post-processors are anyway returning null.The idea of this PR is to hold an additional list of smart post-processors that can be used to minimize the iteration overhead in cases where only
SmartInstantiationAwareBeanPostProcessor
instances are of interest. Applying this patch shows the following results in the profiling and saves around 1-2 seconds for me:Let me know what you think.
Cheers,
Christoph