grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Performance Improvement: Enable Lazy Initialization

Open rainboyan opened this issue 2 years ago • 4 comments

Spring Boot 2.2 M1, Provide a configuration option to enable lazy initialisation, see https://spring.io/blog/2019/03/14/lazy-initialization-in-spring-boot-2-2

related issue: https://github.com/grails/grails-core/issues/12500

rainboyan avatar May 05 '22 10:05 rainboyan

Is this ready for review?

puneetbehl avatar May 11 '22 17:05 puneetbehl

@puneetbehl Need more unit tests, and running tests for real projects. In a simple demo project, it's OK now, but in my one complex project, there are strange behavior, some controllers in plugins are not loaded. I have to be sure that this feature doesn't have many side effects.

rainboyan avatar May 12 '22 16:05 rainboyan

When enable lazy initialization in Grails 5.1.8-SNAPSHOT, in a newly created application, the amount of beans reduced from 353 to 124 during application startup, total 229 beans are not be created and its dependencies will not be injected.

In my real project, there are two beans should not be initialized lazily, gormDispatchEventRegistrar and convertersConfigurationInitializer. They could be excluded from lazy initialization by using LazyInitializationExcludeFilter.

Also, there is a solution, which is to explicitly set bean.lazyInit=false in the bean definition, which is more convenient for Grails users.

rainboyan avatar May 13 '22 16:05 rainboyan

@puneetbehl Do you have time to look at this, and how did you think about it?

rainboyan avatar Jul 06 '22 17:07 rainboyan