Commit 89698ba
authored
Optimize
`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).
Fixes #2723TypeSafeMatching iteration over class methods (#2729)1 parent 70c1fe9 commit 89698ba
File tree
1 file changed
+26
-3
lines changed- src/main/java/org/mockito/internal/invocation
1 file changed
+26
-3
lines changedLines changed: 26 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | 7 | | |
10 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
16 | 27 | | |
17 | 28 | | |
18 | 29 | | |
| |||
39 | 50 | | |
40 | 51 | | |
41 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
42 | 65 | | |
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
46 | | - | |
| 69 | + | |
47 | 70 | | |
48 | 71 | | |
49 | 72 | | |
| |||
0 commit comments