Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TypeSafeMatching no longer iterates over class methods inefficiently
Fixes #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).
- Loading branch information