ipytree icon indicating copy to clipboard operation
ipytree copied to clipboard

Performance while selecting nodes on a "big" tree

Open sdxlzxjh opened this issue 4 years ago • 4 comments

It takes a noticeable period (avg. 3 seconds) to highlight the node to be selected on a relatively big tree, say a thousand leaf nodes with the tree depth of 2. Any idea about improving the performance on big trees?

sdxlzxjh avatar Mar 27 '20 16:03 sdxlzxjh

I have similar issue. I feel like every time I run it, memory footprint rises a lot and it slows down a bit.

I don't know intended scope for the tree, maybe I'm expecting too much or I'm just doing it wrong, but here is example code (for JupyterLab). It's really dumb because it's based on code I'm using, but hopefully that's irrelevant.

from ipytree import Tree, Node

dict_temp = {}
for i in range(1,850):
    dict_temp[i] = str(i) + "hello"

n_a = []
for idx_a, val_a in dict_temp.items():
    if idx_a < 200:
        a_contents = [(idx_a*2)+x+200 for x in range(1,3)]
        n_b = []
        for idx_b in a_contents:
            b_contents = [(idx_a*3)+x+200 for x in range(1,5)]
            n_c = []
            for idx_c in b_contents:
                    name = str(idx_c) + "new"
                    n_c.append(Node(name))
            name = str(idx_b) + "bye"
            n_b.append(Node(name, n_c, show_icon = False, opened = False))
        name = str(idx_a) + "cya"
        n_a.append(Node(name, n_b, show_icon = False, opened = False))

tree = Tree(n_a, multiple_selection = False, animation = 0)
tree.layout.height = '2500px'  

And then next cell to create it:

tree

Ignoring the time it takes to process first cell: If I run this on fresh notebook, it just takes a couple of second to interact with it. But if I run these two cells like 10 times each, it's substantially slower. Especially if I were to change node names in between runs. The main slow down is on clicking a node rather than expanding or closing things

In my use case, I wanted to browse and dynamically edit the tree, so it gets generated quite often.

Is there a command I should be using to 'delete' the tree in between runs or something maybe? Or maybe it is the nodes I should be trying to 'delete'?

eventually it gets to the point where I get prompted to kill the tab and it taking ~40 secs or it taking GBs of memory

insatiablycivil avatar May 08 '21 02:05 insatiablycivil

You are right, this library's widget model's js code needs to be restructured. It currently stores all the created nodes in a global noderegistry (doesn't seem to delete nodes). and every click iterates through all the nodes (even from different trees) and deselects them. It could be made significantly faster with minor changes, but seems like the repo is now unmaintained.

pankajp avatar May 19 '22 04:05 pankajp

I have same issue. I add 800 or more 1000 nodes, error happens.
So I add 500 nodes. If I select node, it is very slow.

deco-dev avatar Oct 21 '22 05:10 deco-dev

#72 I try to fix it.

deco-dev avatar Nov 14 '22 01:11 deco-dev