You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
while doing some loadtests in our project, I noticed that AnnotatedElementUtils.searchWithFindSemantics() or rather AnnotatedElementUtils.findMergedAnnotation() are consuming quite some CPU. It's even above HashMap.getNode(int, Object) in some tests, which I find quite precarious for such a utility class. It looks like this is especially true for using @Order somewhere in the application in combination with @EventListener functionality.
I was wondering if this could be improved in any way? Maybe by caching merged annotation lookups much like in AnnotationUtils. Or maybe by just caching the order in the ApplicationListener context.
Since findMergedAnnotation is indeed an expensive lookup call, we aim for caching the outcome in appropriate places. This is fortunately straightforward in the present case here: ApplicationListenerMethodAdapter initializes an order field on construction now, simply returning the value from getOrder().
Great. Saw your commit already. Just out of curiosity - are the ApplicationListenerMethodAdapter instances created only once at startup? Or are they created over and over again? The latter would be still quite intense for the new constructor behaviour, don't you think?
EventListenerMethodProcessor creates one ApplicationListenerMethodAdapter per annotated method and registers the instance via ConfigurableApplicationContext.addApplicationListener directly, so we should be good here.
Activity
spring-projects-issues commentedon Aug 30, 2016
Juergen Hoeller commented
Since
findMergedAnnotationis indeed an expensive lookup call, we aim for caching the outcome in appropriate places. This is fortunately straightforward in the present case here:ApplicationListenerMethodAdapterinitializes anorderfield on construction now, simply returning the value fromgetOrder().spring-projects-issues commentedon Aug 30, 2016
Christoph Dreis commented
Great. Saw your commit already. Just out of curiosity - are the
ApplicationListenerMethodAdapterinstances created only once at startup? Or are they created over and over again? The latter would be still quite intense for the new constructor behaviour, don't you think?spring-projects-issues commentedon Aug 30, 2016
Juergen Hoeller commented
EventListenerMethodProcessorcreates oneApplicationListenerMethodAdapterper annotated method and registers the instance viaConfigurableApplicationContext.addApplicationListenerdirectly, so we should be good here.spring-projects-issues commentedon Aug 30, 2016
Christoph Dreis commented
Perfect. Thanks again :-)
spring-projects-issues commentedon Aug 31, 2016
Stéphane Nicoll commented
I second that!