dunnock / react-sigma

Lightweight React library for drawing network graphs built on top of SigmaJS
https://dunnock.github.io/react-sigma/
MIT License
258 stars 43 forks source link

enableEdgeHovering efficiency #50

Open bt2414 opened 6 years ago

bt2414 commented 6 years ago

I was trying a 700 nodes and 1600 edges graph. If I don't set the "enableEdgeHovering", the graph will be rendered in a second.

However, if I set "enableEdgeHovering:true", it will have a 4 second delay before rendering the graph.

I know to set "enableEdgeHovering" will affect performance, but 4 second delay is too big.

Could you take a test to see if anything goes wrong? Because I think SigmaJS should not have such a long delay be setting the "enableEdgeHovering" flag.

dunnock commented 6 years ago

Most likely all the extra time is spent building the quadtree index in SigmaJS: https://github.com/jacomyal/sigma.js/blob/9c940aa9b162c7aaaf8b25d88e236cb847c1633a/src/sigma.core.js#L548

For instance, if you are using curve or curvedArrow edges that takes extra time to calculate shape: https://github.com/jacomyal/sigma.js/blob/31cc1ee3baf321d355f5597ba4d7e9fc8e2c6ff2/src/classes/sigma.classes.edgequad.js#L711

Did you check profiler? It should show what consumes most of the time. Also check if you got enough of free RAM.

bt2414 commented 6 years ago

Thanks for your replay. I also tried curvedArrow but it doesn't affect the performance. Could you take a look at my code?


        <Sigma
          style={{width:"100%", height:"720px", backgroundColor:"#19193b"}}
          renderer="canvas"
          graph={this.state.bigGraph}
          settings={{
            drawEdges: true,
            drawLabels: true,
            drawEdgeLabels: false,
            labelThreshold: 0,
            enableEdgeHovering:true,
            edgeHoverExtremities: true,
            defaultLabelColor:"#dddddd",
          }}
        >
          <EdgeShapes default="curvedArrow" />
          <ForceLink
            worker={true}
            barnesHutOptimize={false}
            slowDown={5}
            gravity={1}
            timeout={10000}
          />
          <RandomizeNodePositions />
          <RelativeSize initialSize={15} />
        </Sigma>

If I remove the "enableEdgeHovering:true", it works good without any delays even if I set the "curvedArrow".

Do you think it is normal? Why "enableEdgeHovering" doesn't have the same performance with "EdgeSphapes"?

Thanks so much.

bt2414 commented 6 years ago

I think you are right, it is the building of the quadtree index consumes time. I try to remove this piece of code, it works good.

        if (
          c.edgequadtree !== undefined &&
          c.settings('drawEdges') &&
          c.settings('enableEdgeHovering')
        ) {
          c.edgequadtree.index(this.graph, {
            prefix: c.readPrefix,
            bounds: {
              x: bounds.minX,
              y: bounds.minY,
              width: bounds.maxX - bounds.minX,
              height: bounds.maxY - bounds.minY
            }
          });
        }

But do you think 3 seconds delay is normal?

dunnock commented 6 years ago

If you set edge shapes to line it should work faster, curved and curvedArrow are slower because it calculates curve edges.

<EdgeShapes default="line"/>

https://github.com/dunnock/react-sigma/blob/master/DOCS.md#edgeshapes