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

Limit reflective operations in BeanInstanceSupplier with Spring AOT #32834

Closed
sdeleuze opened this issue May 16, 2024 · 1 comment
Closed

Limit reflective operations in BeanInstanceSupplier with Spring AOT #32834

sdeleuze opened this issue May 16, 2024 · 1 comment
Assignees
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

Comments

@sdeleuze
Copy link
Contributor

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.

@sdeleuze sdeleuze added type: enhancement A general enhancement theme: aot An issue related to Ahead-of-time processing labels May 16, 2024
@sdeleuze sdeleuze added this to the 6.2.0-M3 milestone May 16, 2024
@jhoeller jhoeller added the in: core Issues in core modules (aop, beans, core, context, expression) label May 16, 2024
@sdeleuze sdeleuze modified the milestones: 6.2.0-M3, 6.2.0-M4 May 20, 2024
@snicoll snicoll self-assigned this May 22, 2024
@snicoll snicoll modified the milestones: 6.2.0-M4, 6.2.x Jun 7, 2024
@snicoll snicoll removed their assignment Aug 20, 2024
@jhoeller jhoeller modified the milestones: 6.2.x, 6.2.0-RC2 Sep 17, 2024
@sdeleuze
Copy link
Contributor Author

sdeleuze commented Sep 26, 2024

I confirm that the number of reflective invocations is down from 1049 to 213 with Spring Framework 6.2.0-SNAPSHOT on my Petclinic sample application, thanks for taking care of that enhancement @jhoeller!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants