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

Optimize default property editor allocations for bean instance creation #34361

Closed
sdeleuze opened this issue Feb 3, 2025 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Feb 3, 2025

While working on another issue, I found that ResourceEditorRegistrar#registerCustomEditors is invoked for each bean via AbstractBeanFactory#initBeanWrapper, which in turn create a bunch of PropertyEditor instances.

If we take the use case of a small Spring Boot applications with mostly infrastructure singletons and let say 1 controller and 1 repository with web and data-jdbc starters, we have 229 beans created at startup. If we add the actuator starter, 407 beans. That means ResourceEditorRegistrar#registerCustomEditors is invoked respectively 229 and 407 times for a very small Spring Boot applications, so there is quite a lot of allocation for very little concrete use (I suspect Spring Boot infra is not using custom property editors extensively).

PropertyEditor instances are stateful, so there are some constraints, but while discussing with @jhoeller we were wondering if it could be possible to instantiate those "default custom property editors" lazily like we do for default ones, or alternatively reuse instances if we can.

That could potentially speedup the startup time and reduce the memory allocation of all Spring applications, reducing the GC pressure as well.

@sdeleuze sdeleuze added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Feb 3, 2025
@jhoeller jhoeller self-assigned this Feb 4, 2025
@jhoeller jhoeller added this to the 6.2.3 milestone Feb 4, 2025
@jhoeller jhoeller changed the title Explore optimizing custom property editor allocations Optimize default property editor allocations for bean instance creation Feb 4, 2025
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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants