Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Improvment on clustering performance (almende#3862)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Menighin authored and mojoaxel committed Jun 9, 2019
1 parent ade8e67 commit ba802cd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/network/modules/Clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1222,7 +1221,7 @@ class ClusterEngine {
_updateState() {
let nodeId;
let deletedNodeIds = [];
let deletedEdgeIds = [];
let deletedEdgeIds = {};

/**
* Utility function to iterate over clustering nodes only
Expand Down Expand Up @@ -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;
}
});

Expand All @@ -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;
}
});
});
Expand All @@ -1309,7 +1308,7 @@ class ClusterEngine {
}

if (!edge.endPointsValid() || !isValid) {
deletedEdgeIds.push(edgeId);
deletedEdgeIds[edgeId] = edgeId;
}
});

Expand All @@ -1325,7 +1324,7 @@ class ClusterEngine {
}

edge.clusteringEdgeReplacingIds = this._filter(edge.clusteringEdgeReplacingIds, function(id) {
return deletedEdgeIds.indexOf(id) === -1;
return !deletedEdgeIds[id];
});
});

Expand Down

0 comments on commit ba802cd

Please sign in to comment.