Performance impact of using aop

前端 未结 9 2300
小蘑菇
小蘑菇 2020-12-05 02:07

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 impa

相关标签:
9条回答
  • 2020-12-05 02:39

    In theory, if you use AOP do to what you could do with hard coupling, there is no performance issue, no overhead and no extra method calls unless you weave for nothing. AOP Framework offers you a way to remove the hard coupling and factorize your cross-cutting concern.

    In practice, AOP Framework can introduce 3 types of overhead:

    • fire-time
    • interception mechanic
    • consumer integration (way to develop an advice)

    For more details you can refer to when-is-aop-code-executed.

    Just be careful how you implement an advice because transversal code is a temptation for boxing/unboxing and reflection (expensive in term of performance).

    Without an AOP Framework (hard coupling your cross-cutting concerns) you can develop your presumed advices (dedicated for each treatment) easier without boxing/unboxing and reflection.

    You have to know that most AOP Framework don't offer the way to avoid totally boxing/unboxing and reflection.

    I developed one to respond to most of missing needs concentrated to 3 things :

    • user friendly (lightweight, easy to learn)
    • transparent (no breaking code to include)
    • efficient (no boxing/unboxing, no reflection in nominal user code and good interception mechanic)

    You can find my open source project here : Puresharp API .net 4.5.2+ previously NConcern .NET AOP Framework

    0 讨论(0)
  • 2020-12-05 02:40

    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/

    0 讨论(0)
  • 2020-12-05 02:43

    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 :)

    0 讨论(0)
提交回复
热议问题