Commit b5e080a
authored
Improve performance for transitive dependency checks (#1381)
`TransitiveDependencyCondition` internally calls `contains()`
recursively on the collection of all objects to be tested. If this
collection is a large list and there are enough recursive calls to
`getDirectDependencyTargetsOutsideOfAnalyzedClasses()` this results in a
heavy performance impact. On a reasonable large project a single test
using that condition may take minutes to complete.
Here is a 30 seconds FlameGraph taken while an transitive check was
running for > 2 minutes:

Based on the samples, the CPU hangs in [this filter
lamdba](https://github.com/TNG/ArchUnit/blob/main/archunit/src/main/java/com/tngtech/archunit/lang/conditions/TransitiveDependencyCondition.java#L91)
for > 86% of the time:
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(47,247,323 samples, 0.03%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(44,447,761 samples, 0.03%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(10,837,882,731 samples, 7.32%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(13,262,127,759 samples, 8.96%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(12,668,650,362 samples, 8.56%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(15,368,403,186 samples, 10.38%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(46,224,364 samples, 0.03%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(47,314,101 samples, 0.03%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(18,048,208,277 samples, 12.19%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(13,405,921,387 samples, 9.06%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(93,152,524 samples, 0.06%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(3,244,023,882 samples, 2.19%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(919,865,902 samples, 0.62%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(6,438,577,874 samples, 4.35%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(6,760,263,856 samples, 4.57%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(7,031,313,250 samples, 4.75%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(7,723,048,585 samples, 5.22%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(11,918,050,716 samples, 8.05%)
- TransitiveDependencyCondition$$Lambda$553.0x000000080121ca88:::test
(46,026,822 samples, 0.03%)
So, converting the given list to a Set with much better `contains()`
performance fixes this issue.File tree
1 file changed
+3
-2
lines changed- archunit/src/main/java/com/tngtech/archunit/lang/conditions
1 file changed
+3
-2
lines changedLines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
0 commit comments