From f4992a6ae2c58cae599697db90d8ebe8520e7496 Mon Sep 17 00:00:00 2001 From: Yuki Inoue Date: Thu, 14 Apr 2016 11:52:01 +0900 Subject: [PATCH] Cache child count in maven-graph-plugin Currently, the recursiveChildCount is not cached and this calculation is run everytime. It is likely the weight calculation algorithm is being exponential in time complexity. By caching the recursiveChildCount, this intractability problem is solved. --- .../fusesource/mvnplugins/graph/DependencyVisualizer.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/maven-graph-plugin/src/main/java/org/fusesource/mvnplugins/graph/DependencyVisualizer.java b/maven-graph-plugin/src/main/java/org/fusesource/mvnplugins/graph/DependencyVisualizer.java index 12b4730..c4e9009 100755 --- a/maven-graph-plugin/src/main/java/org/fusesource/mvnplugins/graph/DependencyVisualizer.java +++ b/maven-graph-plugin/src/main/java/org/fusesource/mvnplugins/graph/DependencyVisualizer.java @@ -66,6 +66,7 @@ private class Node { private final ArrayList parents = new ArrayList(); private final Artifact artifact; private int roots; + private int recursiveChildCount = -1; public Node(String id, Artifact artifact) { this.id = id; @@ -202,6 +203,11 @@ private boolean isExclusivelyType(String value) { } public int getRecursiveChildCount() { + + if (recursiveChildCount >= 0) { + return recursiveChildCount; + } + int rc = children.size(); for (Edge child : children) { int t = child.getRecursiveChildCount(); @@ -209,6 +215,7 @@ public int getRecursiveChildCount() { rc = t; } } + recursiveChildCount = rc; return rc; }