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). Right now, 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 injected in any injection point
- does not declare a producer which is injected in any injection point
- TODO
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
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 excluded. |