Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the dirty dependency graph walk #27633

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -282,28 +283,23 @@ private DependencyNode resolveRuntimeDeps(CollectRequest request) throws AppMode
@Override
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context)
throws RepositoryException {
final Set<ArtifactKey> visited = new HashSet<>();
final Map<DependencyNode, DependencyNode> visited = new IdentityHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the Collections.newSetFromMap() utility is sometimes also nice :-)

final Set<ArtifactKey> visited = Collections.newSetFromMap(new IdentityHashMap<>());

for (DependencyNode c : node.getChildren()) {
walk(c, visited);
}
return resolver.getSession().getDependencyGraphTransformer().transformGraph(node, context);
}

private void walk(DependencyNode node, Set<ArtifactKey> visited) {
if (node.getChildren().isEmpty()) {
private void walk(DependencyNode node, Map<DependencyNode, DependencyNode> visited) {
if (visited.put(node, node) != null || node.getChildren().isEmpty()) {
return;
}
final Set<ArtifactKey> deps = artifactDeps
.computeIfAbsent(DependencyUtils.getCoords(node.getArtifact()),
k -> new HashSet<>(node.getChildren().size()));
for (DependencyNode c : node.getChildren()) {
final ArtifactKey key = getKey(c.getArtifact());
if (!visited.add(key)) {
continue;
}
deps.add(key);
deps.add(getKey(c.getArtifact()));
walk(c, visited);
visited.remove(key);
}
}
});
Expand Down