macka Blog

Deep tree syndrome

Have you ever had to build a treeview control for a website and then find once in production people start complaining about slow response times?

It appears that most of the treeview controls I've come across work in one of two ways:

1) they load all of the data for the tree in one go - (for trees with more than 100 nodes - this is BAAADDDD!!!)

2) they require a server-round trip resulting in the whole tree being re-rendered! - (not very elegant)

Neither solution is ideal.  Why should we bother loading in the whole tree when the chances are that the user only ever wants to look at a very small fraction of the tree ?!

The MSDN site uses a treeview for navigation, but it only loads the nodes as they are needed (sometimes you'll see the loading label appear for a fraction of a second).  This type of "deep tree" is ideal when you need to present a hierarchy comprising of thousands of nodes.  When you expand a node the JavaScript requests an XML file for the nodes children.  These children are then cached and added to the tree. 

Aurigma have provided a great guide on how to build one of these deep trees.  I use a variation on this with the tree modelled within SQL Server as nested sets. If you need to perform a tree re-sync (ie. reload the tree with the nodes expanded to the node you request) then you can extract the required nodes in a single SELECT statement.

Legacy Comments

re: Deep tree syndrome

Could you perhaps post your code so that I can see how you are using DeepTree with SQL?