@@ -17,6 +17,7 @@ import com.autonomousapps.model.internal.intermediates.DependencyTraceReport.Kin
17
17
import com.autonomousapps.model.internal.intermediates.Reason
18
18
import com.autonomousapps.visitor.GraphViewReader
19
19
import com.autonomousapps.visitor.GraphViewVisitor
20
+ import com.google.common.graph.Graphs
20
21
import org.gradle.api.DefaultTask
21
22
import org.gradle.api.file.DirectoryProperty
22
23
import org.gradle.api.file.RegularFile
@@ -373,19 +374,25 @@ private class GraphVisitor(
373
374
context : GraphViewVisitor .Context ,
374
375
): Boolean {
375
376
val superGraph = context.superGraph
377
+ val externalSupers = context.project.externalSupers
376
378
377
379
// collect all the dependencies associated with external supers
378
- val requiredExternalClasses = context.project.externalSupers.asSequence()
379
- .flatMap { external -> superGraph.reachableNodes(false ) { it.className == external } }
380
- .mapNotNull { node ->
381
- val deps = node.deps.filterToOrderedSet { dep ->
380
+ // nb: we start by iterating over `supergraph.nodes()`, and then filtering, as that is _far more efficient_
381
+ // then iterating over `externalSupers` and then calling `supergraph.nodes()` repeatedly: I have observed graphs
382
+ // with hundreds of thousands of nodes. This is why we use Guava directly here rather than going through our own
383
+ // Graphs wrapper. There's a yet-to-be-published update to the wrapper that does this for us.
384
+ val requiredExternalClasses = superGraph.nodes().asSequence()
385
+ .filter { superNode -> superNode.className in externalSupers }
386
+ .flatMap { superNode -> Graphs .reachableNodes(superGraph, superNode) }
387
+ .mapNotNull { superNode ->
388
+ val deps = superNode.deps.filterToOrderedSet { dep ->
382
389
// If dep has just one parent and it's the root, then we must retain that edge
383
390
val graph = context.graph.graph
384
391
graph.parents(dep).singleOrNull { it == graph.root() } != null
385
392
}
386
393
387
394
if (deps.isNotEmpty()) {
388
- SuperNode (node .className).apply { this .deps + = deps }
395
+ SuperNode (superNode .className).apply { this .deps + = deps }
389
396
} else {
390
397
null
391
398
}
0 commit comments