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

BeanFactoryUtils.transformedBeanName() creates a lot of GC pressure [SPR-17151] #21688

Closed
spring-projects-issues opened this issue Aug 9, 2018 · 3 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 9, 2018

Dave Syer opened SPR-17151 and commented

This is something that popped up while analysing a pathological Spring Data app with 2000 repositories, but it points at a potential general optimization that might help in Spring. The problem is that BeanFactoryUtils.transformedBeanName() is called for every bean in the context when someone wants to do DefaultListableBeanFactory.getBeansOfType() which is quite common in Spring Data and Spring Boot (and other frameworks). This in turn creates a new String for every factory bean which in turn shows up in the GC pressure graph in Flight Recorder (25% of GC pressure on startup of this extreme example). If the results were somehow cacheable in DefaultListableBeanFactory that would help.


Affects: 5.0.8

Referenced from: commits eddbf13

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 9, 2018

Juergen Hoeller commented

So you mean the substring that temporarily strips the & prefix is causing the GC pressure here? The initial concatenation of prefix + bean name does not show as much?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 9, 2018

Dave Syer commented

Yes, that was it (the substring).

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 9, 2018

Juergen Hoeller commented

That's a bit surprising... We also concatenate the prefix with the bean name in quite a few places, easily as often as the inverse transformation. I suppose these somehow end up in the JVM's String pool whereas the substring call always creates a new String programmatically.

In any case, I'll try to cache those transformed names in a ConcurrentHashMap. Sounds over the top for a simple prefixed String but it nevertheless seems to matter. It has been raised to me before by a performance engineer, BTW... but not with concrete numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.