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

OnClassCondition tries to determine the outcome for single auto-configuration classes in parallel #22294

Conversation

dreis2211
Copy link
Contributor

@dreis2211 dreis2211 commented Jul 9, 2020

Hi,

I just noticed that a vanilla Spring-Boot app (with web, security and actuator starters) creates 200+ threads on startup. After a small investigation those threads turned out to be created by OnClassCondition. I noticed that threads are created even though the passed autoConfigurationClasses array has a length of 1. (Only one invocation in the lifetime of the app has multiple classes passed). In those cases it seems to be wasteful to create threads because the work cannot be split in half, really.

A small benchmark shows the following results:

Baseline New
2.783 2.570
2.811 2.562
2.760 2.690
2.707 2.704
2.732 2.576
2.646 2.659
2.816 2.803
2.847 2.578
2.765 2.670
2.722 2.731
Mean 2.759 2.654
Range 0.201 0.241

Let me know what you think.
Cheers,
Christoph

Prior to this commit, OnClassCondition started a thread even if the number of
passed autoconfiguration class candidates never exceeded 1. This commit only
starts a thread if there is actually work to split in half.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 9, 2020
@wilkinsona
Copy link
Member

Nice find, @dreis2211! Thank you.

The behaviour you've observed is a regression in Spring Boot 2.3. In 2.2 the filtering is only performed once for all of the auto-configuration classes. In 2.3, it's performed for all of the auto-configuration classes but then, as you have observed, it's performed many more times a single auto-configuration class at a time. I haven't yet had a chance to figure out why that is, but there may be an even bigger improvement to be found that restores 2.2's behaviour.

@wilkinsona
Copy link
Member

6921fda introduced the change in behaviour. That was a good change to make. What you have proposed will just make it better. Thanks again.

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 9, 2020
@wilkinsona wilkinsona added this to the 2.3.x milestone Jul 9, 2020
@dreis2211
Copy link
Contributor Author

I found this commit as well and didn't consider it a regression. Thanks for keeping me in the loop.

@wilkinsona wilkinsona changed the title Reduce started threads in OnClassCondition OnClassCondition tries to determine the outcome for single auto-configuration classes in parallel Jul 9, 2020
@wilkinsona
Copy link
Member

@dreis2211 While you were working on this, I'm curious if you tried avoiding the creation of the StandardOutcomeResolver where there's only a single auto-configuration class involved? I'll give it a go if you haven't already tried it. I'm not sure it'll make a noticeable difference, but I think it's worth checking.

@dreis2211
Copy link
Contributor Author

@wilkinsona I haven't because that seemed like it wouldn't be worth the effort. But feel free to give it a try.

@wilkinsona wilkinsona self-assigned this Jul 14, 2020
wilkinsona pushed a commit that referenced this pull request Jul 14, 2020
Prior to this commit, OnClassCondition started a thread even if the number of
passed autoconfiguration class candidates never exceeded 1. This commit only
starts a thread if there is actually work to split in half.

See gh-22294
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.3.2 Jul 14, 2020
@wilkinsona
Copy link
Member

Thanks again, @dreis2211. I've yet to try avoiding creating the StandardOutcomeResolver. We're planning some more performance work during 2.4's development so we'll look at it then if needed.

@dreis2211
Copy link
Contributor Author

Thanks @wilkinsona . Let me know if I can help with the performance work in any way.

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.

None yet

3 participants