From 65730dc9a5f5441499fca304c1f6f315e3051674 Mon Sep 17 00:00:00 2001 From: hongtao Date: Tue, 2 Sep 2014 21:55:31 -0700 Subject: [PATCH] Fix memory usage issue caused by adding same node multiple times This issue happens when multiple nodes share same target node, and will consume lots of memory and slow down the layout calculation greatly when a graph being rendered is close to a complete bipartite graph at each step of the flow. --- sankey/sankey.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sankey/sankey.js b/sankey/sankey.js index c3bc59f..012f4f2 100644 --- a/sankey/sankey.js +++ b/sankey/sankey.js @@ -117,8 +117,10 @@ d3.sankey = function() { remainingNodes.forEach(function(node) { node.x = x; node.dx = nodeWidth; - node.sourceLinks.forEach(function(link) { - nextNodes.push(link.target); + node.sourceLinks.forEach(function (link) { + if (nextNodes.indexOf(link.target) == -1) { + nextNodes.push(link.target); + } }); }); remainingNodes = nextNodes;