Skip to content

Small memory improvements to InjectionMetadata and InitDestroyAnnotationBeanPostProcessor.LifecycleMetadata [SPR-9264] #13902

Closed
@spring-projects-issues

Description

@spring-projects-issues

Philippe Marschall opened SPR-9264 and commented

We analysed the memory usage of our application and found a lot of empty LinkedHashSet/Collections.synchronizedSet in the following three cases:

org.springframework.beans.factory.annotation.InjectionMetadata.injectedElements


* 

```

org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.LifecycleMetadata.initMethods


* 

```

org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.LifecycleMetadata.destroyMethods


There are two things that can be done to address this:
1. Creating a LinkedHashSet of the "right" size, eg. the default capacity is 16 but the exact capacity is known in advance
1. If the argument is empty then we use Collections.emptySet() which is a constant so no additional memory is used. Since it's immutable there is no need for the Collections.synchronizedSet wrapper.

Affects: 3.1 GA

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions