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

Reduce footprint due to RootBeanDefinition [SPR-11343] #15967

Closed
spring-projects-issues opened this issue Jan 21, 2014 · 1 comment
Closed

Reduce footprint due to RootBeanDefinition [SPR-11343] #15967

spring-projects-issues opened this issue Jan 21, 2014 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 21, 2014

AdiB opened SPR-11343 and commented

Related to #12149
RootBeanDefinition members (externallyManagedConfigMember, externallyManagedInitMethods,externallyManagedDestroyMethods) are initialized even if not in use.
Setting ConcurrentHashMap initial size as 0 is not good enough it still allocates a map with ~ 10 empty elements.

Should delay the initialization.

For example -

public void registerExternallyManagedConfigMember(Member configMember) {
    if (externallyManagedConfigMembers == null){
        externallyManagedConfigMembers = new ConcurrentHashMap<Member, Boolean>(0);
    }
	this.externallyManagedConfigMembers.put(configMember, Boolean.TRUE);
}

public boolean isExternallyManagedConfigMember(Member configMember) {
    if (externallyManagedConfigMembers == null){
        return false;
    }
	return this.externallyManagedConfigMembers.containsKey(configMember);
}

Affects: 3.2.6, 4.0 GA

Issue Links:

  • #12149 Reduce footprint due to BeanDefinitions

Referenced from: commits d9ab6aa, a599b57

Backported to: 3.2.7

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 22, 2014

Juergen Hoeller commented

Looking at the current code paths that call those methods, we can conveniently reuse the existing postProcessingLock which will typically be active already when registerExternallyManaged* calls come in from the bean factory's post-processing phase. Since that's a regular synchronized lock, we can also safely lazily initialize regular HashSets for those externallyManaged* holders.

Note that with ConcurrentHashMaps, lazily initializing them introduces a race condition. Simply speaking, ConcurrentHashMaps need to be initialized as final fields, otherwise we'd need some form of synchronization for the lazy creation of each ConcurrentHashMap itself.

Juergen

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