Limit reflective operations in BeanInstanceSupplier
with Spring AOT
#32834
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
theme: aot
An issue related to Ahead-of-time processing
type: enhancement
A general enhancement
Milestone
While profiling https://github.com/sdeleuze/petclinic-efficient-container runtime with AOT mode enabled, I noticed that
org.springframework.beans.factory.aot.BeanInstanceSupplier
is performing a lot (1049 for my use case for an app with 433 beans) reflective factory method retrievals.This is likely done to be able to support use cases like proxied factory method and
@Qualifier
, but I am wondering if we could improve the AOT processing to skip this reflective retrieval for the common use case since it seems to shave a few ms of startup time and reduces the GC pressure / memory consumption (reported by the profiling).With this quick and dirty branch that skips the reflective retrieval when there is a generator defined (it breaks proxied factory method and
@Qualifier
), I was able to reduce to 209 (from 1049) the count of reflective factory method retrieval.It would be great to explore with @jhoeller and @snicoll if we can introduce an optimization that skips such reflective factory method retrieval for the common use case (no proxy, no
@Qualifier
since Spring Boot uses that for most of its auto configurations). Maybe we can also review what is done for bean constructors in a similar fashion.The text was updated successfully, but these errors were encountered: