iVis-at-Bilkent / cytoscape.js-expand-collapse

A Cytoscape.js extension to expand/collapse nodes for better management of complexity of compound graphs
MIT License
126 stars 37 forks source link

Collapse a large compound node is slow #114

Open bensonnw opened 4 years ago

bensonnw commented 4 years ago

In our project, we have a compound node contains more than 17000 nodes, when collapsing it, it takes about 30 seconds. After some investigation, the API expandCollapseUtilities.removeChildren is taking most of the time, it seems like the following code inside the For loop is pretty expensive:

  ......
  var removedChild = child.remove();
  if (root._private.data.collapsedChildren == null) {
    root._private.data.collapsedChildren = removedChild;
  }
  else {
    root._private.data.collapsedChildren = root._private.data.collapsedChildren.union(removedChild);
  }

Instead of doing that, how about to move the code out of the loop and do something:

if (children.length > 0) {
  const removedChildren = children.remove();
  if (root._private.data.collapsedChildren == null) {
    root._private.data.collapsedChildren = removedChildren;
  }
  else {
    root._private.data.collapsedChildren = root._private.data.collapsedChildren.union(removedChildren);
  }
} 

This way needs much less time (drop to about 1 second) to run.

hasanbalci commented 4 years ago

@bensonnw Thanks for your suggestion, we will evaluate it before the next release.

bensonnw commented 4 years ago

@hasanbalci Thanks for quick response, would you mind to tell me when is your next release?