Skip to content

Commit 65d6eb1

Browse files
committed
perf(analyzer): Avoid unnecessary graph reconstruction
Previously, in any case where multiple package managers were found the dependency graphs were reconstructed in the process to replace package manager dependencies. This even happened when no package manager dependencies were present. Avoid this expensive operation if possible by exiting early if no package manager dependencies are present. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 2448370 commit 65d6eb1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

analyzer/src/main/kotlin/AnalyzerResultBuilder.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,22 @@ class AnalyzerResultBuilder {
116116
private fun AnalyzerResult.resolvePackageManagerDependencies(): AnalyzerResult {
117117
if (dependencyGraphs.size < 2) return this
118118

119-
logger.info { "Resolving package manager dependencies across ${dependencyGraphs.size} graphs." }
120-
121119
val handler = PackageManagerDependencyHandler(this)
122120
val navigator = DependencyGraphNavigator(dependencyGraphs)
123121

122+
// Exit early if no graph contains placeholder nodes for package manager dependencies to avoid expensive graph
123+
// reconstruction in those regular cases.
124+
val hasPackageManagerDependencies = dependencyGraphs.any { (packageManagerName, graph) ->
125+
graph.scopes.any { (_, rootIndices) ->
126+
val nodes = navigator.dependenciesAccessor(packageManagerName, graph, rootIndices)
127+
nodes.any { it.isPackageManagerDependency }
128+
}
129+
}
130+
131+
if (!hasPackageManagerDependencies) return this
132+
133+
logger.info { "Resolving package manager dependencies across ${dependencyGraphs.size} graphs." }
134+
124135
// Resolve package manager dependencies by constructing new graphs that have the placeholder nodes replaced with
125136
// copies of the referenced nodes.
126137
val graphs = dependencyGraphs.mapValues { (packageManagerName, graph) ->

0 commit comments

Comments
 (0)