Before M4.5 objects were instantiated using a ComponentProvider which eventually delegated to Classes.getClassFactory().newInstance(). With M4.5 IoC was introduced and the current ComponentProvider info.magnolia.objectfactory.guice.GuiceComponentProvider is no longer aware of the ClassFactory. However, as the DefaultClassFactory can be replaced with a custom one (like e.g. our Groovy module does) that means that instantiating new objects with a custom class factory no longer works. This particularly affects the Groovy module and its ability to replace Java classes in config with Groovy ones and hot deploy and change them on the fly.
It was decided to make our current default ComponentProvider aware of ClassFactory again. This will happen through ObjectManufacturer which is eventually used to create class instances. The new interface will be implemented by custom class factories and ObjectManufacturer will call the interface's new method delegating to the custom cf which will try to re-load (by recompiling if necessary) the class.
Some concerns were expressed as to a performance penalty due to this additional check but, as far as I could see in my basic measurements, the overload seems to be negligible.
Here I am comparing the execution time of ObjectManufacturer.newInstance() with and without my changes. The table shows most of the classes instantiated by Magnolia when rendering the home page of the travel demo. The largest numbers are of course for the Groovy foo.TestModel class especially when it needs recompiling cause the source has changed (more precisely because it's newer).
|Class name||execution time without changes||with changes||Groovy source changed (with changes)|
|info.magnolia.context.DefaultRepositoryStrategy||0.10556 ms||1.553202 ms||-|
|info.magnolia.module.site.ExtendedAggregationState||0.023335 ms||0.01753 ms||-|
|info.magnolia.context.SystemRepositoryStrategy||0.091537 ms||0.096238 ms||-|
|info.magnolia.context.DefaultRepositoryStrategy||0.146448 ms||0.049374 ms||-|
|info.magnolia.module.site.ExtendedAggregationState||0.014709 ms||0.012665 ms||-|
|info.magnolia.rendering.util.FilteringAppendableWrapper||0.015895 ms||0.023665 ms||-|
|info.magnolia.rendering.engine.FilteringResponseOutputProvider||0.119688 ms||0.082204 ms||-|
|info.magnolia.rendering.listeners.AreaFilteringListener||0.122445 ms||0.102501 ms||-|
|info.magnolia.rendering.model.RenderingModelImpl||0.676595 ms||0.108454 ms||-|
|info.magnolia.context.SystemRepositoryStrategy||0.098068 ms||0.501442 ms||-|
|info.magnolia.templating.elements.PageElement||0.144661 ms||0.117432 ms||-|
|info.magnolia.templating.elements.AreaElement||0.218534 ms||0.063254 ms||-|
|info.magnolia.rendering.model.RenderingModelImpl||0.150412 ms||0.092489 ms||-|
|info.magnolia.templating.elements.AreaElement||0.188307 ms||0.11792 ms||-|
|foo.TestModel||0.393441 ms||5.328067 ms (overhead due to check if needs recompilation)||496.362892 ms (overhead due to check and recompilation)|