Description
Affects: Spring Framework 5.3.2
I have a project (console based, environment=NONE, only base spring boot starter) with a lot of prototype bean creations at application runtime (not startup), ~15k of beans. I have one interface and near 150 different implemantions of it marked with
@Component
@Primary
@Scope("prototype")
@Configuration
has @Bean
-method, some kind of object provider, which get bean of concrete class (not interface):
@Configuration
@RequiredArgsConstructor
public class DiagnosticConfiguration {
private final ApplicationContext applicationContext;
@Bean
@Scope("prototype")
public <T extends BSLDiagnostic> T diagnostic(Class<T> clazz) {
return applicationContext.getBean(clazz);
}
}
On spring boot 2.3.5 15000 of diagnostic
calls take 12 seconds. On spring boot 2.4.1 - more than 75 seconds. no changes to application code or configs, just dependency bump.
On flame graph I discovered problem (synchonized issue) at CommonAnnotationBeanPostprocessor.findResourceMetadata
https://postimg.cc/3ywf5B6Q
Comparison of:
2.3.5: https://postimg.cc/HVdnQYLn
2.4.1: https://postimg.cc/KKw4LtKh
Looks like all bean creations on 2.3.5 took metadata from cache, while all creations at 2.4.1 have "cache miss" and are forced to recreate metadata.
I've asked about this at spring-boot gitter and was redirected here by @wilkinsona.
P.S. I'll try to provide some demo-project, need some time to reproduce it.