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

Support early class filtering for @ConditionalOnBean, @ConditionalOnSingleCandidate and @ConditionalOnWebApplication #13328

Closed
YannCebron opened this issue Jun 1, 2018 · 5 comments
Assignees
Labels
theme: performance Issues related to general performance type: enhancement A general enhancement
Milestone

Comments

@YannCebron
Copy link

YannCebron commented Jun 1, 2018

Proposal:

For known Condition implementations, we "know" that they technically contain a "virtual" @ConditionalOnClass condition.

Sample:
org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition#isServletWebApplication effectively equals @ConditionalOnClass("org.springframework.web.context.support.GenericWebApplicationContext") performed by corresponding ClassUtils.isPresent() call.

Benefits:

  1. Improved startup time for application
  2. Improved performance in IDEs using such metadata (as IntelliJ IDEA already does)

TBD: How can such knowledge be provided/maintained for any custom Condition implementation wishing to participate in this metadata generation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 1, 2018
@philwebb
Copy link
Member

philwebb commented Jun 1, 2018

I'm not sure we can do that. The OnWebApplicationCondition#isServletWebApplication method is only called for @ConditionalOnWebApplication(type=SERVLET) so it's not always the case that we can filter those auto-configuration class out early.

Perhaps I've misunderstood the suggestion?

@YannCebron
Copy link
Author

True, is it not possible to evaluate annotation attribute values in annotation processor?

@philwebb
Copy link
Member

philwebb commented Jun 1, 2018

Possibly. I think I'd rather make OnWebApplicationCondition a AutoConfigurationImportFilter and filter out configurations directly there. I don't like the idea of adding too much knowledge to the annotation processor.

@snicoll
Copy link
Member

snicoll commented Jun 1, 2018

That would also duplicate the knowledge about the target type. But perhaps there is something else that could be made. Like @ConditionalOnBean(Foo.class) on @Configuration translates to @ConditionalOnClass(Foo.class). If Foo.class isn't on the classpath, there is no need to load the class at all.

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Jun 4, 2018
@philwebb philwebb self-assigned this Jun 6, 2018
@philwebb philwebb added this to the Backlog milestone Jun 6, 2018
@philwebb philwebb added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Jun 13, 2018
@YannCebron
Copy link
Author

w/r to previous comment, this is the list for SB 2.0.3 (includes all listed starters from start.spring.io)

@ConditionalOnBean w/o @ConditionalOnClass: (38)
  de.codecentric.boot.admin.server.cloud.config.AdminServerDiscoveryAutoConfiguration
  de.codecentric.boot.admin.server.config.AdminServerAutoConfiguration
  de.codecentric.boot.admin.server.config.AdminServerHazelcastAutoConfiguration
  de.codecentric.boot.admin.server.ui.config.AdminServerUiAutoConfiguration
  io.pivotal.spring.cloud.service.config.VaultTokenRenewalAutoConfiguration
  org.apache.camel.model.rest.springboot.RestConfigurationDefinitionAutoConfiguration
  org.apache.camel.spring.boot.cloud.CamelCloudAutoConfiguration
  org.apache.camel.spring.boot.cloud.CamelCloudServiceCallConfigurationAutoConfiguration
  org.apache.camel.spring.boot.cloud.CamelCloudServiceChooserAutoConfiguration
  org.apache.camel.spring.boot.cloud.CamelCloudServiceDiscoveryAutoConfiguration
  org.apache.camel.spring.boot.cloud.CamelCloudServiceFilterAutoConfiguration
  org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration
  org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration
  org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration
  org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration
  org.springframework.cloud.client.hypermedia.CloudHypermediaAutoConfiguration
  org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration
  org.springframework.cloud.consul.discovery.RibbonConsulAutoConfiguration
  org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationAutoConfiguration
  org.springframework.cloud.netflix.eureka.config.EurekaDiscoveryClientConfigServiceAutoConfiguration
  org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration
  org.springframework.cloud.netflix.zuul.ZuulProxyAutoConfiguration
  org.springframework.cloud.sleuth.annotation.SleuthAnnotationAutoConfiguration
  org.springframework.cloud.sleuth.instrument.async.AsyncCustomAutoConfiguration
  org.springframework.cloud.sleuth.instrument.async.AsyncDefaultAutoConfiguration
  org.springframework.cloud.sleuth.instrument.messaging.TraceMessagingAutoConfiguration
  org.springframework.cloud.sleuth.instrument.scheduling.TraceSchedulingAutoConfiguration
  org.springframework.cloud.sleuth.instrument.web.TraceHttpAutoConfiguration
  org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration
  org.springframework.cloud.sleuth.instrument.web.TraceWebFluxAutoConfiguration
  org.springframework.cloud.sleuth.instrument.web.TraceWebServletAutoConfiguration
  org.springframework.cloud.sleuth.instrument.web.client.TraceWebClientAutoConfiguration
  org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsBinderSupportAutoConfiguration
  org.springframework.cloud.stream.config.ChannelBindingAutoConfiguration
  org.springframework.cloud.stream.reactive.ReactiveSupportAutoConfiguration
  org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration
  org.springframework.cloud.zookeeper.discovery.RibbonZookeeperAutoConfiguration
  org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryAutoConfiguration

@philwebb philwebb added the theme: performance Issues related to general performance label Aug 31, 2018
philwebb added a commit that referenced this issue Sep 24, 2018
Add `FilteringSpringBootCondition` base class and refactor the existing
`OnClassCondition` to use it. Also update the `match` method so that
the `autoConfigurationClasses` array may include `null` elements.

See gh-13328
philwebb added a commit that referenced this issue Sep 24, 2018
Update the auto-configuration annotation processor to generate
properties for `@ConditionalOnBean` and `@ConditionalOnSingleCandidate`.

See gh-13328
philwebb added a commit that referenced this issue Sep 24, 2018
Update `OnBeanCondition` to be an `AutoConfigurationImportFilter` and
filter out classes early.

See gh-13328
philwebb added a commit that referenced this issue Sep 24, 2018
Update the auto-configuration annotation processor to generate
properties for `@OnWebApplication`.

See gh-13328
philwebb added a commit that referenced this issue Sep 24, 2018
@philwebb philwebb changed the title Proposal: generate "virtual @ConditionalOnClass" entry in spring-autoconfigure-metadata.properties for known conditions Support early class filtering for @ConditionalOnBean, @ConditionalOnSingleCandidate and @ConditionalOnWebApplication Sep 24, 2018
@philwebb philwebb modified the milestones: 2.1.x, 2.1.0.M4 Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: performance Issues related to general performance type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants