views:

1382

answers:

5

We have started to use spring aop for cross cutting aspects of our application (security & caching at the moment).

My manager worries about the performance impact of this technology although he fully understands the benefits.

My question, did you encounter performance problems introduced by the use of aop (specifically spring aop)?

+6  A: 

When I used it, I didn't - but then my application isn't your application.

If you use it for calls which are used in a very tight loop, there's the opportunity for a significant performance hit. If it's just used to check security once per request and cache various things, I can't see how it's likely to be significant - but that's why you should profile and benchmark your app.

I realise that "measure with your app" probably isn't the answer you were looking for, but it may well be the one you guessed you'd get :)

Jon Skeet
yes indeed expected. I was hoping I could a link to this post when arguing why benchmarking isn't necessary. :-)
LiorH
+1  A: 

If you are using proxy-based AOP, you are talking about 1 additional Java method invocation per aspect applied. The performance impact there is pretty negligible. The only real concern is the creation of the proxies but this usually happens just once on application startup. The SpringSource blog has a great post on this:

http://blog.springsource.com/2007/07/19/debunking-myths-proxies-impact-performance/

cliff.meyers
really? why do I see so many method calls(~5) in the stack trace when debugging?
LiorH
Could you post the stack trace? I may have been incorrect and forgot that there are a few extra calls into the reflection API for the proxy to call the target. Are you using JDK or CGLIB proxies?
cliff.meyers
+5  A: 

As long as you have control of your AOP I think it's efficient. We did have performance problems anyway, so by own reasoning we were not fully in control ;) This was mostly because it's important that anyone that writes aspects has full understanding of all the other aspects in the system and how they interrelate. If you start doing "smart" things you can outsmart yourself in a jiffy. Doing smart things in a large project with lots of people who only see small parts of the system can be very dangerous performance-wise. This advice probably applies without AOP too, but AOP lets you shoot yourself in the foot in some real elegant ways.

Spring also uses proxying for scope-manipluations and thats an area where it's easy to get undesired performance losses.

But given that you have control, the only real pain point with AOP is the effect on debugging.

krosenvold
+4  A: 

If performance is going to be a concern, we have used AspectJ to great effect.

Because it uses bytecode weaving (compile time vs. runtime makes quite the difference) it's one of the fastest AOP frameworks out there. See: AOP Benchmarks

Nathan
A: 

i have used spring AOP in a batch process in my current project to transaction manage a database.

At first, it was figured that there wouldn't be a performance problem, but we didn't figure into the equation that we called the database thousands of times. one aspect call in aop doesn't effect performance much, but multiply that by thousands, and it turns out the new system was worse than the old one, due to these extra method calls.

I'd say that aop is a great system to use, but try to take note on how many methods calls are added to your application

Richard