Skip to content

Commit

Permalink
Improve performance for transitive dependency checks
Browse files Browse the repository at this point in the history
`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. Converting the given
list to a Set with much better `contains()` performance fixes this issue.

on-behalf-of: @e-solutions-GmbH <[email protected]>
Signed-off-by: To6i <[email protected]>
  • Loading branch information
To6i committed Nov 20, 2024
1 parent 987104a commit 54a4c9d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Set;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.tngtech.archunit.PublicAPI;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
Expand All @@ -41,7 +42,7 @@ public final class TransitiveDependencyCondition extends ArchCondition<JavaClass

private final DescribedPredicate<? super JavaClass> conditionPredicate;
private final TransitiveDependencyPath transitiveDependencyPath = new TransitiveDependencyPath();
private Collection<JavaClass> allClasses;
private Set<JavaClass> allClasses;

public TransitiveDependencyCondition(DescribedPredicate<? super JavaClass> conditionPredicate) {
super("transitively depend on classes that " + conditionPredicate.getDescription());
Expand All @@ -51,7 +52,7 @@ public TransitiveDependencyCondition(DescribedPredicate<? super JavaClass> condi

@Override
public void init(Collection<JavaClass> allObjectsToTest) {
this.allClasses = allObjectsToTest;
this.allClasses = ImmutableSet.copyOf(allObjectsToTest);
}

@Override
Expand Down

0 comments on commit 54a4c9d

Please sign in to comment.