Skip to content

Improve performance of ReflectionUtils#getUniqueDeclaredMethods [SPR-10197] #14830

Closed

Description

@spring-projects-issues

Thusinthan Kajendran opened SPR-10197 and commented

There is a start up performance issue, if I configure beans for an application with JavaConfig (JavaConfing with more than 100 beans). The time to create the beans increases significantly more than when I configured the beans via XML-Based. I have performed a profile on the project and found that the problem lies in the MethdoeRefelctionUtils. getUniqueDeclaredMethods()( This method try to filteries out overrided methods from superclass).

But if I break the JavaConfig down into smaller files (each file 10 beans), than the start will be performed quickly. I'm well aware that it is better to have smaller files, however, it is the algorithm of the method RefelctionUtils.getUniqueDeclaredMethods () badly designed when more than 100 beans......


Affects: 3.1.2

Attachments:

Issue Links:

1 votes, 5 watchers

Activity

  1. spring-projects-issues commented on Jan 21, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Hi Thusinthan,

    I've just attempted to reproduce this issue without any success. Take a look at commit cb8dc73. Try this yourself by building from source, just ensure that you do the following once you've cloned the repository locally:

    git checkout 3.2.x
    ./gradlew :spring-core:cleanTest :spring-core:test -Dtest.single=ReflectionUtilsTests -PtestGroups="performance"
    

    As you can see, I'm testing to ensure that a class with 100 methods is processed by ReflectionUtils#getUniqueDeclaredMethods in under 10 milliseconds. This should be fast enough for any purposes.

    Let us know if you can modify this test to reproduce your issue. Alternatively, feel free to submit a reproduction project per the instructions at https://github.com/SpringSource/spring-framework-issues#readme

    Thanks!

  2. spring-projects-issues commented on Jan 21, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Thusinthan Kajendran commented

    Hi,

    your are right, your test actually requries only 10 milliseconds for 100 Methods because you have tested the isolated refelctionmethod. The Problem only accurs in combination with SpringBeans. If you configure with JavaConfig, your SpringBeans will take 92 millisecondsds for 100 beans. I also tired my test with 300 Beans and the result is 6248 milliseconds.

    Please find my test-case as attachment.

    Thanks
    Thusinthan

  3. spring-projects-issues commented on Jan 21, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Thusinthan Kajendran commented

    The UnitTest with sample JavaConfig

  4. spring-projects-issues commented on May 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Anders Wallgren commented

    Another problem with this method is that it gets called repeatedly for the same class (I suppose that could be considered a problem with the caller, but nonetheless).

    This method could really benefit from caching.

  5. spring-projects-issues commented on May 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Note that, after the initial report of this issue here, #16501 introduced a cache for ReflectionUtils.getDeclaredMethods already which is also being used through getUniqueDeclaredMethods(). Is the extra filtering in getUniqueDeclaredMethods() really so much extra overhead that it's worth some extra caching there?

    Juergen

  6. spring-projects-issues commented on May 10, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Anders Wallgren commented

    See screenshot from profiling session -- it would appear so. After implementing the cache in my fork of Spring, time to run this test was reduced from 2 minutes to 20 seconds.

  7. added
    status: waiting-for-triage
    type: enhancement
    in: core
    and removed
    type: enhancement
    on Jan 11, 2019
  8. added
    status: bulk-closed
    and removed
    status: waiting-for-triage
    on Jan 11, 2019
  9. spring-projects-issues commented on Jan 12, 2019

    @spring-projects-issues
    CollaboratorAuthor

    Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: corestatus: bulk-closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions