Optimize default property editor allocations for bean instance creation #34361
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
While working on another issue, I found that
ResourceEditorRegistrar#registerCustomEditors
is invoked for each bean viaAbstractBeanFactory#initBeanWrapper
, which in turn create a bunch ofPropertyEditor
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.
The text was updated successfully, but these errors were encountered: