Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeSafeMatching no longer iterates over class methods inefficiently #2729

Merged
merged 1 commit into from Aug 13, 2022

Commits on Aug 13, 2022

  1. TypeSafeMatching no longer iterates over class methods inefficiently

    Fixes mockito#2723.
    
    Class.getMethods is an inefficient method call which is being called on
    each mock invocation. It ends up constructing new Method objects for
    each method on the class, and this can dominate the overall performance
    of Mockito mocks. This commit caches the result of the computation.
    
    Once concern is that this change uses some static state. I considered:
    
    - Instance state - based on where this type is constructed it seemed
      like it'd be a big imposition on code readability elsewhere.
    - Weakly referenced map. Mockito has a type for this, but the
      constructor of that type produces a Thread with which to clean up.
    
    Both of these seemed like overkill compared to the overhead expected
    in the real world (which should be on the order of a few kilobytes of
    RAM at most).
    j-baker committed Aug 13, 2022
    Copy the full SHA
    c7312d3 View commit details
    Browse the repository at this point in the history