-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Optimize constructor dependency injection performance for parameter name matches #28122
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
I can see how getting bean name lookup could be interesting in some cases. We do have support for @jhoeller let's make up our mind on this? |
In a micro-benchmark with 3000 bean definitions with distinct bean classes and 3000 injection points requesting each of those beans, this new shortcut for parameter names matching the target bean names led to ~10x better autowiring performance. These assumptions will never consistently apply to real-life scenarios, but even for a fraction of the beans involved, the performance benefit should be noticeable. Common parameter names and bean names are expected to match the convention already. Application setups can be explicitly designed for better autowiring performance through choosing consistent parameter names that match the target bean names, or alternatively through assigning aliases to the target beans that match the common parameter names declared in the application. |
If initializing bean via constructor dependency injection, Spring will do the candidates look-up by parameter type (essentially via
BeanFactoryUtils#beanNamesForTypeIncludingAncestors
) which is really slow if application getting huge. We are searching an approach to tell Spring to look-up candidates by constructor's parameter name.I've read the code in
ConstructorResolver
but cannot find a way to achieve constructor dependency injection by parameter name. By the way there is a similar question on Stack Overflow: Spring autowire by name constructor arguments, there is just a work-around but not solution.Can Spring support this feature if parameter name is available in runtime?
Affects: <All Spring Framework versions>
The text was updated successfully, but these errors were encountered: