Skip to content

Performance Degradation in getBean method after upgrade #22537

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

Closed
Srikalpana opened this issue Mar 7, 2019 · 6 comments
Closed

Performance Degradation in getBean method after upgrade #22537

Srikalpana opened this issue Mar 7, 2019 · 6 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided type: regression A bug that is also a regression

Comments

@Srikalpana
Copy link

Srikalpana commented Mar 7, 2019

Hi Team,

We have a requirement where we generate java classes dynamically and register them using Spring registerBean. When we upgraded Spring framework, 4.2.3 to 4.3.18, there was a severe performance degradation while retrieving the registered bean.

To fix the issue, we are planning to use the following code instead of using getBean method. My question is: does the below API provide same initialization (like autowiring / pre & post processing capacity) or not? Will there be any repercussion with this API?

AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
return ( T )factory.autowire( clazz, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false );
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 7, 2019
@sdeleuze
Copy link
Contributor

sdeleuze commented Mar 7, 2019

Could be a duplicate of #22425.

@jhoeller jhoeller self-assigned this Mar 7, 2019
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Mar 7, 2019
@jhoeller
Copy link
Contributor

jhoeller commented Mar 7, 2019

Programmatically creating an autowired instance that way works in principle. However, if you want post-processors (including annotation-driven injection) to work, you should rather use the AutowireCapableBeanFactory.createBean method: simply createBean(clazz) will be sufficient, no need to pass in any autowiring constants (unless you actually want property-driven autowiring rather than annotation-driven autowiring, along the lines of the old autowire setting for an XML bean definition).

That said, any details on the performance regression in your scenario? I assume it is about getBean(Class) (which goes through a type-based resolution algorithm) rather than getBean(String) (which performs a straight map lookup by key)? Does the issue actually look like a duplicate of #22425 to you? Are you seeing the performance degradation on first retrieval or on repeated retrieval of a bean?

@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 7, 2019
@Srikalpana
Copy link
Author

Thank you for the response. Both getBean(Class) & getBean(String) methods are showing performance degradations. We badly need a work around for this issue, as it is taking more than 3 min during initialization.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 13, 2019
@Srikalpana
Copy link
Author

AutowireCapableBeanFactory.createBean(clazz) also did not give us any benefit , it is taking > 3 min.

@sdeleuze
Copy link
Contributor

@Srikalpana Could you provide us a repro project or even a private access to the project sources in order to allow us to analyze what's going on?

@jhoeller
Copy link
Contributor

Closing due to the lack of reproducibility and the EOL of the 4.3.x line. To be reopened or followed up if concrete suggestions for a refinement come in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants