Skip to content
Permalink
Browse files

evaluator: Visit dependencies only once per scope in dependency rules

For projects with many scopes and repetitive dependency tress, like
Android Gradle projects, visiting the full dependency trees can take a
significant amount of time, with no added value for visiting the same
dependencies several thousand times.

Instead keep a list of all already visited subtrees per scope and
make sure that each subtree is only visited once.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@here.com>
  • Loading branch information...
mnonnenmacher committed May 10, 2019
1 parent 1194af1 commit 672eef7c4d556db707bc94d456000d9868f94bc0
Showing with 12 additions and 3 deletions.
  1. +12 −3 evaluator/src/main/kotlin/RuleSet.kt
@@ -75,8 +75,16 @@ class RuleSet(val ortResult: OrtResult) {
ancestors: List<PackageReference>,
level: Int,
scope: Scope,
project: Project
project: Project,
visitedPackages: MutableSet<PackageReference>
) {
if (visitedPackages.contains(pkgRef)) {
log.debug { "Skipping rule $name for already visited dependency ${pkgRef.id.toCoordinates()}." }
return
}

visitedPackages += pkgRef

val curatedPackage = ortResult.analyzer?.result?.let { analyzerResult ->
analyzerResult.packages.find { it.pkg.id == pkgRef.id }
?: analyzerResult.projects.find { it.id == pkgRef.id }?.toPackage()?.toCuratedPackage()
@@ -105,14 +113,15 @@ class RuleSet(val ortResult: OrtResult) {
}

pkgRef.dependencies.forEach { dependency ->
traverse(dependency, listOf(pkgRef) + ancestors, level + 1, scope, project)
traverse(dependency, listOf(pkgRef) + ancestors, level + 1, scope, project, visitedPackages)
}
}

ortResult.analyzer?.result?.projects?.forEach { project ->
project.scopes.forEach { scope ->
val visitedPackages = mutableSetOf<PackageReference>()
scope.dependencies.forEach { pkgRef ->
traverse(pkgRef, emptyList(), 0, scope, project)
traverse(pkgRef, emptyList(), 0, scope, project, visitedPackages)
}
}
}

0 comments on commit 672eef7

Please sign in to comment.
You can’t perform that action at this time.