react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

LinkLayerWidget panning performance

Open JokerNN opened this issue 9 years ago • 4 comments

Hello!

First of all, thanks for the awesome library, I really like this huge amount of work you've done. So far this is the best diagraming library I could found. And I totally agree with 2 layers approach (SVG + absolute positioned HTML).

The question I would like to raise here is how LinkLayerWidget performs while panning the diagram. Take a look at this GIF Before

If link has bend points - it becomes "wavy" during panning.

The reasons I found for this is the following:

  1. LinkFactory creates new element every time it is requested. And it's requested every single panning tick.
  2. React.cloneElement clones just created link in LinkLayerWidget.tsx:66

I fiddled with it a little bit, and here is what I tried For the first one I tried to implement link cache in my factory. It's pretty straightforward (https://gist.github.com/JokerNN/760a400189caa6facd8ae782aa1dcf11)

For the second one I have no ability to override LinkLayerWidget logic, so I removed cloning for testing purposes.

Updated result doesn't handle node dragging properly, but here how it performs: After

Question 1: So can you please give me any tips/further ideas on how I can overcome this lagging and excessive cloning? Question 2: If I will succeed with optimization I'm happy to submit PR if you're accepting

JokerNN avatar Sep 12 '17 16:09 JokerNN

Clone element is not the problem, its actually relatively fast. The problem is that the link start and end points needs to be calculated from the absolutely positioned div. These DOM calls are slow and happen as you move the canvas. I have a fix that I'm still experimenting with, but the problem you are experiencing is only when there are an excessive amount of nodes on the screen. With 20 or so nodes, its barely noticeable.

dylanvorster avatar Sep 12 '17 19:09 dylanvorster

basically the problem is actually here: https://github.com/projectstorm/react-diagrams/blob/master/src/widgets/LinkLayerWidget.tsx#L44

dylanvorster avatar Sep 12 '17 19:09 dylanvorster

@dylanvorster you're absolutely right, it's great that you're working on it already

JokerNN avatar Sep 13 '17 16:09 JokerNN

Fixed! (hopefully) http://dylanv.blog/2017/09/13/storm-react-diagrams-v3/

dylanvorster avatar Sep 13 '17 22:09 dylanvorster