Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AOP performance overhead

Tags:

c#

aop

I've been searching a bit for some performance tests about typical AOP tasks. I've not been able to find any though, could you help me? I'm mostly thinking about Castle, Unity and perhaps PostSharp, even though it might be too expensive for my project.

like image 216
Karsten Avatar asked Jan 03 '11 10:01

Karsten


2 Answers

I haven't seen any quantitative comparisons, too, so this answer is probably far from being complete.

It is difficult to compare performance of Castle or Unity with PostSharp - Castle and Unity use runtime weaving by dynamic proxying and PostSharp adds overhead at compile stage. So if performance is crucial for you, compiled solutions like PostSharp will always be better. Generating AOP proxies in runtime means dynamic generating IL code and heavy reflection use.

So performance tests that could make sense have to compare solutions using the same technique - you can try to compare Castle Dynamic Proxy and Unity Interception proxy implementation.

I don't know the former well, but in case of latter, there are still three different scenarios to compare - transparent proxies (MarshalByRefObject), interface proxies and subclassing proxies - each with its own set of usage scenarios and its own performance overheads. From what I've read, transparent proxy is horribly slow and shouldn't be used in AOP scenarios. Interface and subtyping proxies generates some IL on the fly and this is the same what Castle DP does so I believe the differences shouldn't be so big (but again, no quantitative results here).

like image 131
NOtherDev Avatar answered Sep 18 '22 08:09

NOtherDev


If you are looking for a light weight AOP tool, there is a article "Add Aspects to Object Using Dynamic Decorator" (http://www.codeproject.com/KB/architecture/aspectddecorator.aspx). It is thin and flexible.

It describes an approach to adding aspects to object at runtime instead of adding aspects to class at design time. The advantage of this approach is that you decide if you need an aspect when you use an object.

Most of today's AOP tools define aspects at class level at class design time. And you don't have the flexibility when you use an object of the classes.

like image 23
Gary Avatar answered Sep 18 '22 08:09

Gary