Skip to content

Optimize ordered event listener performance [SPR-14642] #19208

Closed

Description

@spring-projects-issues

Christoph Dreis opened SPR-14642 and commented

Hey,

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.

!annotated_element_utils_jmc.jpg|thumbnail!

Cheers,
Christoph


Affects: 4.3.2

Attachments:

Issue Links:

Referenced from: commits 58fa63f, 3b91dec

Activity

  1. spring-projects-issues commented on Aug 30, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    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().

  2. spring-projects-issues commented on Aug 30, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Christoph Dreis commented

    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?

  3. spring-projects-issues commented on Aug 30, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    EventListenerMethodProcessor creates one ApplicationListenerMethodAdapter per annotated method and registers the instance via ConfigurableApplicationContext.addApplicationListener directly, so we should be good here.

  4. spring-projects-issues commented on Aug 30, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Christoph Dreis commented

    Perfect. Thanks again :-)

  5. spring-projects-issues commented on Aug 31, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    I second that!

  6. added
    type: enhancement
    in: core
    on Jan 11, 2019
  7. added this to the 4.3.3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions