Skip to content
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

AbstractAutoProxyCreator.getCacheKey generate lots of String garbage [SPR-13655] #18231

Closed
spring-projects-issues opened this issue Nov 7, 2015 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 7, 2015

Vladimir Gordiychuk opened SPR-13655 and commented

Current implementation of getCacheKey uses string concatenation: https://github.com/spring-projects/spring-framework/blob/master/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java#L306-L308

This leads to two problems:

  1. Excessive heap garbage due to throw-away string creation
  2. Excessive CPU due to computing hash code for the newly created strings.

In our spring context present 1200+ beans and ~20 beanPostProcessors as result E2E spenario for 30 minute generate ~300GB char[]
!spring_get_cachekey.png|thumbnail!

It our problem that legacy part of system use BeanFactory.getBean instead of inject dependency correctly. But problem described above also affect application start time because spring for inject dependency also do getBean by Class and as result spring for each class iterate by all beans in context and generate cache key like:

protected Object getCacheKey(Class<?> beanClass, String beanName) {
     return beanClass.getName() + "_" + beanName;
}

!spring_allocation_string_by_start.png|thumbnail!

!spring_hot_methods_by_start.png|thumbnail!


Affects: 4.2.2

Attachments:

Issue Links:

Referenced from: commits 7b711c4

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 7, 2015

Vladimir Gordiychuk commented

I prepare pull request and submit it right now

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 7, 2015

Vladimir Gordiychuk commented

Pull request #913

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 13, 2015

Juergen Hoeller commented

After some further consideration, AbstractAutoProxyCreator uses a prefixed bean name as its cache key now: either with the FactoryBean prefix "&" or just the plain bean name, depending on a type check. We therefore align it with our own recommendation in the BeanPostProcessor.postProcessAfterInitialization callback javadoc.

Juergen

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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants