Skip to content

Optimize AbstractAutowireCapableBeanFactory.populateBean(String, RootBeanDefinition, BeanWrapper) to avoid redundant Java Bean introspection [SPR-16918] #21457

@spring-projects-issues

Description

@spring-projects-issues

Andy Wilkinson opened SPR-16918 and commented

In a typical Spring Boot app, a significant amount of the startup cost is due to org.springframework.beans.CachedIntrospectionResults.forClass(Class<?>). There's a direct cost in terms of the CPU time taken for introspection and a secondary cost due to increased memory usage and GC pressure.

In the vast majority of cases, the introspection results are retrieved beneath AbstractAutowireCapableBeanFactory.populateBean(String, RootBeanDefinition, BeanWrapper) so that it can retrieve the property descriptors and then filter them. If I short-circuit populateBean so that it returns early if the bean definition's property values are empty, an app that took 2.7 seconds to start then starts in as little as 2.3 seconds.

The short circuiting loses two pieces of functionality:

  1. The opportunity for InstantationAwareBeanPostProcessors to add property values
  2. @Required support

Boot itself doesn't make use of either of these so the current ~400ms cost is a high price to pay. I'd like to explore the possibility of lowering or removing this cost.

As far as I can tell only one of the built-in post-processors, RequiredAnnotationBeanPostProcessor, uses the property descriptors, and it only does so if the bean definition hasn't been marked to skip the required check. One possibility may be to retrieve the property descriptors lazily and for Boot to somehow mark its bean definitions with skipRequiredCheck.


Affects: 5.0.6

Issue Links:

Referenced from: commits 81cb740

0 votes, 6 watchers

Metadata

Metadata

Assignees

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