Skip to content

ScheduledBeanLazyInitializationExcludeFilter is auto-configured even when annotation-based scheduled has not been enabled#33276

Closed
hpoettker wants to merge 1 commit into
spring-projects:2.6.xfrom
hpoettker:conditional-lazy-init-filter
Closed

ScheduledBeanLazyInitializationExcludeFilter is auto-configured even when annotation-based scheduled has not been enabled#33276
hpoettker wants to merge 1 commit into
spring-projects:2.6.xfrom
hpoettker:conditional-lazy-init-filter

Conversation

@hpoettker

Copy link
Copy Markdown
Contributor

This PR makes the exposure of ScheduledBeanLazyInitializationExcludeFilter conditional on the annotation @EnableScheduling.

When the property spring.main.lazy-initialization is set to true, the LazyInitializationBeanFactoryPostProcessor currently applies the ScheduledBeanLazyInitializationExcludeFilter to each bean definition. This is independent of whether the user has opted in to scheduling with @EnableScheduling or not.

The goal of the PR is to improve the start-up performance of applications that use lazy initialization but not scheduling. An example could be a short-lived Spring Batch app that contains multiple job beans but executes only a single job when started and exits afterwards. Such an app would not use scheduling and profits from not initializing all beans on start up.

I've assembled a toy application with a flame graph here: https://github.com/hpoettker/lazy-scheduler-demo

About 3% of the whole application run-time is spent on the ScheduledBeanLazyInitializationExcludeFilter.

The start-up time (as logged by the application) varies between runs. But on my machine it's about 0.65 seconds and reduces to 0.60 seconds when the TaskSchedulingAutoConfiguration is excluded.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 19, 2022
@wilkinsona wilkinsona changed the title Let ScheduledBeanLazyInitializationExcludeFilter be conditional on @EnableScheduling ScheduledBeanLazyInitializationExcludeFilter is auto-configured even when annotation-based scheduled has not been enabled Nov 21, 2022
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 21, 2022
@wilkinsona wilkinsona added this to the 2.6.x milestone Nov 21, 2022
@snicoll snicoll self-assigned this Nov 21, 2022
@snicoll snicoll modified the milestones: 2.6.x, 2.6.14 Nov 21, 2022
@snicoll snicoll closed this in 48e77ee Nov 21, 2022
@snicoll

snicoll commented Nov 21, 2022

Copy link
Copy Markdown
Member

Thanks again @hpoettker

@hpoettker hpoettker deleted the conditional-lazy-init-filter branch November 21, 2022 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants