Browse Source

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.
develop
João Menighin 6 years ago
committed by Yotam Berkowitz
parent
commit
77e16a508b
1 changed files with 7 additions and 8 deletions
  1. +7
    -8
      lib/network/modules/Clustering.js

+ 7
- 8
lib/network/modules/Clustering.js View File

@ -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];
});
});

Loading…
Cancel
Save