From ee5d2b5c072c47444a901374d3d3993364af1553 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Thu, 23 Jan 2025 12:47:41 +0100 Subject: [PATCH] fix: skip deep comparison for Gradle projects This is unnecessary and leads to a long runtime (and possible an infinite loop/recusrsion) for large dependency graphs as observed in https://github.com/oss-review-toolkit/ort/issues/9763 --- model/src/main/kotlin/utils/DependencyGraphBuilder.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/model/src/main/kotlin/utils/DependencyGraphBuilder.kt b/model/src/main/kotlin/utils/DependencyGraphBuilder.kt index 4b20e8f4aba51..004f54c7c28c1 100644 --- a/model/src/main/kotlin/utils/DependencyGraphBuilder.kt +++ b/model/src/main/kotlin/utils/DependencyGraphBuilder.kt @@ -335,6 +335,12 @@ class DependencyGraphBuilder( val dependencies2 = dependencies.associateBy { dependencyHandler.identifierFor(it) } if (!dependencies2.keys.containsAll(dependencies1)) return false + if (dependencyHandler::class.simpleName == "GradleDependencyHandler") { + // In case of Gradle, we can skip the costly deep comparison. + // If the dependencies are the same, their children are also the same. + if (dependencies2.keys.sorted() == dependencies1.sorted()) return true + } + return ref.dependencies.all { refDep -> dependencies2[dependencyIds[refDep.pkg]]?.let { dependencyTreeEquals(refDep, it) } == true }