|
From: Chris N. <ch...@si...> - 2003-12-02 20:58:40
|
Rod Johnson wrote:
> "CGLIB subclass optimizations" mean that methods with no advice aren't
> overridden. This gives a 2x performance boost for non-advised methods
> (excluding the work of the method, which may of course be more
> significant). However, there are some tradeoffs to be aware of in certain
> cases:
>
> - To do this, the original target is copied fieldwise into the instance of
> the enhanced class. This means that the original class must have a no-arg
> constructor. Also if the old target was registered as a listener for other
> objects, the new class won't be.
> - This doesn't work with pooling, thread local or other "dynamic"
> TargetSources: only for a single shared instance
> - It's impossible to change the target or TargetSource or advice
> thereafter.
Given these constraints, the CGLIB2 option ("option #1") of using a "shell"
proxy and dispatching back to the original bean seems like the way to go.
By using the Dispatcher instead of LazyLoader you can make the proxy work
for dynamic target sources with only a slight performance hit. Plus you do
not need to do the fieldwise copying. I believe the performance would be
similar to OptimizedCglib1AopProxy but should work for *any* bean. When you
switch to CGLIB2 I'll put together an example patch.
BTW in all cases you could use CGLIB2 to optimize away the check against
EQUALS_METHOD and Advised.class by shunting them to their own interceptors
using a CallbackFilter.
Chris
|