question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rendering of large trees is slow (1000+ nodes)

See original GitHub issue

I have a tree with over 1000 nodes and it is taking a long time to render (45+ seconds). I’ve tried a few things to tidy that up (the browser layout stage is taking most of the time) but they are not quite working.

As I see it, every node is added to the display and the browser re-renders the layout (time-consuming). If I set the treant-id to display:hidden then back after the render, it is 6 seconds!

However, the render is squashed up into a tiny div! I’m guessing that because the div is hidden during render it has 0 height/width and you are depending on those to render properly.

I had the idea of trying to render to an unattached DOM element then attaching it, but it did not like that as it needs the #treant-id element to be in the DOM to work.

Would an enhancement be to render the tree to an unattached DOM element before passing it back to the DOM? I’m looking in the codebase now for an opportunity to do this.

Any other ideas for speedups?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
yinxscommented, Jun 21, 2020

Lines has to be drawn to the real document, not fragment. Original description fixed.

Thanks! I implemented all your suggested fixes and it works like a charm. It’s now blazing fast in comparison. I even got it to work in IE (the organization I work for just won’t let that one go) by changing node.remove(); to tree.testArea.removeChild(node); although I hope that was the correct way to do it. Anyway, great fix and thanks again!

1reaction
mpil2commented, Jun 21, 2020

That solution works fine in Chromium based browsers here, but in Firefox everything turned out all wrong. Connectors were drawn away from the nodes, and outside of the divs the were supposed to be drawn into. Nodes couldn’t be interacted with anymore. Maybe it’s something small, but JS is not my strong suit. Too bad, because with around 1500 nodes, speed could definitely use a boost!

Sorry for confusing, my description was slightly misleading, drawing lines in reset function, i.e. line this._R = new Raphael( this.drawArea, 100, 100 ); has to be as the last, just before “return this”. Lines has to be drawn to the real document, not fragment. Original description fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Treeview that contains 20,000 items -> Too slow ... - MSDN
It seems that the tree functions nicely if the nodes don't get much bigger than 75-100 items per node, no matter how many...
Read more >
Avoid an excessive DOM size - Chrome Developers
A large DOM tree in combination with complicated style rules can severely slow down rendering. Memory performance.
Read more >
Dijit tree, how to improve performance for a large tree with ...
Each tree node contains other inner widgets, so it takes long time to render the whole 500 items especially in IE. It may...
Read more >
How to reduce DOM nodes in React's web application ...
Rendering the DOM nodes which will be hidden in the DOM tree ... A large DOM tree can slow down your page performance...
Read more >
Taming huge collections of DOM nodes
Render a configurable number of rows (1000 by default) of randomly ... Having a few thousand DOM nodes to update can be quite...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found