Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2457

Explore the possibilities to drop unused beans metadata after bootstrap to save memory





      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.


      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


      1. Programmatic lookup - no easy way to detect, at least Instance<> injection points should be considered (the only problem is probably CDI.current().select())
      2. EE components might be installed after Weld initialization finished - this cleanup must be performed after all EE components are installed this is a requirement if ALLOW_OPTIMIZED_CLEANUP==true
      3. How to identify application entry points (such as JAX-RS resource) - this will probably require some SPI


      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.


      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.




            mkouba@redhat.com Martin Kouba
            mkouba@redhat.com Martin Kouba
            0 Vote for this issue
            2 Start watching this issue