This is what we try to do:
First implementation was using AspectJ, with point cut:
- If a bean method has an annotation @MyAnnotation, wrap the method with Around Advice.
- Minimal performance impact on runtime calls to the beans.
Very easy to set up, however performance was very slow. I benchmarked it. The reason as far as I can tell is that when you call the bean method, the proxy tries to assemble the list of aspects dynamically. Just put a breakpoint and see how much code runs when you call the bean method. Quite a lot. I could not find a way to make this assembly static, when the proxy is generated. It all happens at runtime each time the bean method is called.
Current implementation is this:
Performance is much better. The advice is resolved and configured at load time, and not when you call the bean method.
<!-- Enable Spring AOP support -->
<property name="exposeProxy" value="false" />
<property name="frozen" value="true" />
<property name="opaque" value="false" />
<property name="optimize" value="true" />
<!-- pointcut advisor -->
<bean class="com.blah.MyMethodInterceptor" />
There is still an overhead of using the aopalliance MethodInterceptor interface and not the CGLIB comparable interface, but this is small comparing to resolving the list of aspects on every bean method call.
The impact on methods that are annotated is ~1:100, and methods that are not annotated in the same bean ~1:10. With AspectJ it was about an order of magnitude slower.
This is acceptable for the application. I think using the CGLIB interceptors directly can improve performance further. However, the major performance impact of dynamic aspect lookups on every method call is solved (verified using debugger). Currently this is sufficient.
If there is a way to use CBLIB directly I would still be interested to know, but its not so important now with the current benchmark results.
Thanks for the interest!
PS. PHP tag makes nice XML color coding