Search code examples
c#performancetreelanguage-agnostic

Improving a big hierarchy tree


I have been working on a project where I need to interface and show a hierarchy from a big database (~100.000 folders, even more files), but it takes 5 minutes to be able to load the data from the database to the project, and I want to reduce it.

My implementation used a tree to represent this data (because it made sense at the beginning), using recursion to navigate down the tree to place new folders and items (which right now are not being used, since I tried to add them but it took so long to populate the tree I just removed them). Are there better structures to hold such hierarchy? Otherwise, is there a better way to transverse the tree (since it seems that most of the time is spent climbing down and up the tree, due to recursion and the fact the database is rather deep)?

I am using C#, but I believe an agnostic answer would be good enough.


Solution

  • You don't need to load everything because you can not see them all in your monitor anyway, you can use:

    1. Lazy loading, load only if user want to, for example if user double click a certain folder
    2. Using Virtualization User Interface or showing only the visible folder

    For user interface virtualization example you can read an watch the Video: Code Canvas