Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flattening of very large data is slow #4

Open
bharatpatil opened this issue Jun 29, 2016 · 4 comments
Open

Flattening of very large data is slow #4

bharatpatil opened this issue Jun 29, 2016 · 4 comments

Comments

@bharatpatil
Copy link

bharatpatil commented Jun 29, 2016

This library is very wonderful.

it seems that flattening of 100,000 nodes takes time. Correct me if I'm wrong.
One approach can be taken where flattening should be done in chunks and that operation should return promise.

@cheton
Copy link
Owner

cheton commented Jun 29, 2016

The "flatten" and "rowRenderer" functions, especially the "rowRenderer", would use the most CPU time while trying to load a large tree:

https://github.com/cheton/infinite-tree/blob/master/src/infinite-tree.js#L686
https://github.com/cheton/infinite-tree/blob/master/src/infinite-tree.js#L712

// Flatten nodes
this.nodes = flatten(data, { openAllNodes: this.options.autoOpen });

// Update rows
this.rows = this.nodes.map(node => this.options.rowRenderer(node, this.options));

One solution is to render only visible rows, it should be able to significantly reduce the rendering time from 10s to <0.1s.

Another workaround is to use lazy loading, you can load first batch of top-level nodes (e.g. 1000 top-level nodes in one batch) at the first time, when you scroll to the bottom, then call tree.addChildNodes(nodes) to load another batch of top-level nodes.

@bharatpatil
Copy link
Author

I guess if already flattened list is provided to loadData() then it would solve problem for 1st line.

@kinow
Copy link

kinow commented Jan 28, 2020

I guess if already flattened list is provided to loadData() then it would solve problem for 1st line.

+1 We are working a similar idea. At the moment we are adding InfiniteTree to a Vue component. We had a component implemented with recursion, and some Vue components that would create their children components on the fly. Which would cause style reflows, event bubbling, and be hard to render when you had ~thousands of nodes.

With the InfiniteTree, the performance is already better. But our GraphQL data is flatten already. We thought we would be able to use it, but in the end had to keep the hierarchical data, and pass if to the new component.

We now want to investigate if it would be possible to skip the step where the flatten data is created. I already know it is possible to create an empty InfiniteTree by not giving it any data in the constructor. If there is a nice way to tell it to load the flatten data, I think this issue will be solved, and the component will be even faster.

@FoolHen
Copy link
Contributor

FoolHen commented Nov 21, 2021

Seems like there was an issue with the flatten library that addChildNodes is using. It was fixed in version 0.11.1 but infinite-tree is still using the previous version. I was having this issue and updating the dependency increased the performance noticeably. Updated in a PR @cheton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants