From 77e16a508b7197f134021ab824d24130a1f2e3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Menighin?= Date: Sat, 31 Mar 2018 16:05:32 -0300 Subject: [PATCH] Improvment on clustering performance (#3862) * Improving the way _updateState deals with deleted edges * Realized can't simply use it as a Set to check existence. Set the value as the edgeId as well. * Removing the 1 line that was making my clustering take 10 seconds to load instead of 1! =D That clone was is not needed once we just clone and check for the join condition. --- lib/network/modules/Clustering.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/network/modules/Clustering.js b/lib/network/modules/Clustering.js index 6d9a1a59..5e862901 100644 --- a/lib/network/modules/Clustering.js +++ b/lib/network/modules/Clustering.js @@ -161,8 +161,7 @@ class ClusterEngine { // collect the nodes that will be in the cluster util.forEach(this.body.nodes, (node, nodeId) => { - let clonedOptions = NetworkUtil.cloneOptions(node); - if (options.joinCondition(clonedOptions) === true) { + if (node.options && options.joinCondition(node.options) === true) { childNodesObj[nodeId] = node; // collect the edges that will be in the cluster @@ -1222,7 +1221,7 @@ class ClusterEngine { _updateState() { let nodeId; let deletedNodeIds = []; - let deletedEdgeIds = []; + let deletedEdgeIds = {}; /** * Utility function to iterate over clustering nodes only @@ -1273,7 +1272,7 @@ class ClusterEngine { util.forEach(this.clusteredEdges, (edgeId) => { let edge = this.body.edges[edgeId]; if (edge === undefined || !edge.endPointsValid()) { - deletedEdgeIds.push(edgeId); + deletedEdgeIds[edgeId] = edgeId; } }); @@ -1282,8 +1281,8 @@ class ClusterEngine { // So the cluster nodes also need to be scanned for invalid edges eachClusterNode(function(clusterNode) { util.forEach(clusterNode.containedEdges, (edge, edgeId) => { - if (!edge.endPointsValid() && deletedEdgeIds.indexOf(edgeId) === -1) { - deletedEdgeIds.push(edgeId); + if (!edge.endPointsValid() && !deletedEdgeIds[edgeId]) { + deletedEdgeIds[edgeId] = edgeId; } }); }); @@ -1309,7 +1308,7 @@ class ClusterEngine { } if (!edge.endPointsValid() || !isValid) { - deletedEdgeIds.push(edgeId); + deletedEdgeIds[edgeId] = edgeId; } }); @@ -1325,7 +1324,7 @@ class ClusterEngine { } edge.clusteringEdgeReplacingIds = this._filter(edge.clusteringEdgeReplacingIds, function(id) { - return deletedEdgeIds.indexOf(id) === -1; + return !deletedEdgeIds[id]; }); });