h2. 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.
h2. 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 h2. Problems: # Programmatic lookup - no easy way to detect, at least {{Instance<>}} injection points should be considered # EE components might be installed after Weld initialization finished - this cleanup must be performed after all EE components are installed
h2. 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.
h2. 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 method- * -must 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|https://github.com/weld/core/blob/master/impl/src/main/java/org/jboss/weld/config/ConfigurationKey.java#L272]}}. |
|