2

I was looking for the option to profile my APIs. I found Spring AOP is one of the options to profile the methods.

There are two options in Spring AOP to configure and use the aspects:

  1. context:load-time-weaver
  2. aop:aspectj-autoproxy

As per my understanding first option (load-time-weaver) performs weaving at load time without creating any proxy objects. And second option (aspectj-autoproxy) creates proxy objects. Am I correct on this? I believe, creation of proxy objects may hit the performance. wouldn't it?

Which option is best to choose considering better performance? What are the pros and cons of both approaches?

kriegaex
  • 63,017
  • 15
  • 111
  • 202
Narendra Verma
  • 2,372
  • 6
  • 34
  • 61

1 Answers1

1

Well, Narendra, first of all there are profilers for profiling software. Maybe there is no need to code anything on your own.

As for your question: I have not idea how to configure Spring because I never use it. I am an AspectJ user. What I do know though, is that Spring AOP always uses proxies (JDK or CGLIB, depending on whether you need to proxy interfaces or classes). This is, as you said, something you probably do not want for profiling. AspectJ, no matter if you use compile or load time weaving, does not need or use proxies and thus should be faster. If you are not already using Spring in your project anyway, I would not touch it just to satisfy your profiling needs. Furthermore, Spring AOP only works for Spring Beans and just offers method interception, not much more. AspectJ is a full-blown AOP implementation and much more powerful. If you are already using Spring, you have a choice of using Spring AOP, AspectJ within Spring or a mixture of both.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Thanks Kriegaex for your response. Still I am not much clear about exact differences between context:load-time-weaver and aop:aspectj-autoproxy. – Narendra Verma May 12 '14 at 06:25
  • Have you read the manual? From what I understand the former activates AspectJ load-time weaving while the latter activates Spring-AOP auto-proxying for Spring beans targeted by pointcuts. While it is possible to use a combination of both approaches for different types of aspects and target classes, I think in your case it would be wise to decide for one lf them only. And my recommendation still is AspectJ for the reasons mentioned in my answer. – kriegaex May 12 '14 at 10:05
  • This article from the guys at Spring compares/contrasts load-time weaving with proxies: http://spring.io/blog/2007/07/19/debunking-myths-proxies-impact-performance/ – StvnBrkdll Mar 02 '16 at 16:05
  • The guy in the article says I am right. Thanks for that. – kriegaex Mar 02 '16 at 21:21