-
Task
-
Resolution: Done
-
Major
-
None
-
None
Motivation
CDI apps usually consist of user business logic, libraries (e.g. DeltaSpike) and integration stuff (e.g. WildFly subsystems - JSF, Bean Validation, Batch). Most applications only use a small part of the beans provided by libraries and integrations. However, Weld has to retain the metadata for all beans in memory.
Measurements showed that a simple bean/producer method takes approx. 1-2 KB. Batch subsystem which is automatically enabled in WildFly registers ~ 60 beans (producers). One could exclude the subsystem completely but this approach has drawbacks. E.g. if you only use one the beans you cannot exclude the whole subsystem/bean archive.
Solution
Allow to instruct Weld to find "unused" beans and drop their metadata after bootstrap. An unused bean:
- is not a built-in bean, extension, interceptor, decorator
- does not have a name
- does not declare an observer
- is not eligible for injection to any injection point
- does not declare a producer which is eligible for injection to any injection point
- is not eligible for injection into any Instance<> injection point
is not a cached result in any TypeSafeBeanResolver (this would mean that it was a result of programmatic lookup during bootstrap, unless an anonymous inner class AnnotationLiteral was used)this one probably does not make much sense- is not an application entry point
Problems:
- Programmatic lookup - no easy way to detect, at least Instance<> injection points should be considered (the only problem is probably CDI.current().select())
EE components might be installed after Weld initialization finished - this cleanup must be performed after all EE components are installedthis is a requirement if ALLOW_OPTIMIZED_CLEANUP==true- How to identify application entry points (such as JAX-RS resource) - this will probably require some SPI
Configuration
User should be able to exclude some beans from removal. E.g. a regular expression might be used to match the bean classes which are included/excluded.
Integrators
We should probably add a new method to org.jboss.weld.bootstrap.api.Bootstrap with the following contract:
optional - an integrator is not required to invoke this methodmust be invoked after Bootstrap.endInitialization() and after all EE components which support injection are installed (i.e. relevant ProcessInjectionTarget was fired)attempts to optimize stored metadata to save memory
See also ConfigurationKey#ALLOW_OPTIMIZED_CLEANUP.