Posted 11 Feb 2011
Link to this post
1st Time Binding ObservableCollection to TreeView Root is lightning fast. But adding more records to an obserable collection after it's already bound is very, very slow.
I'm using the Virtualization.
We have multiple customers who put 50,000 records into the root of the treeview. We have our own framework that calls the server async and populates an observable collecion in the ViewModel with data. Right now, it takes about 30-45 seconds to query data on the server-side. That is our limitation, not yours. Which means if I want to get 50,000 records then the client has to wait 30-45 seconds for the client side to request data, server to retrieve data, and client-side to populate the observable collection with data and bind to the treeview control.
My observations of this scenario:
When getting all 50,000 records at one time then your control loads within seconds (minus our 30-45 second query). It's very fast.
this.FolderTreeView.ItemsSource = null
AddRootNodes(); //add root nodes to observable collection
this.FolderTreeView.ItemsSource = tv.TreeViewSource; //bind observable collection to treeview.
The above performs well
The problem is sending a huge amount of data all at one time. Instead, we want to break up the 50,000 records into 5,000 chucks. This means we would do 10 calls between the client and the server to fill the root of the tree.
Now, If I want to break up the 50,000 into 10 seperate calls between the client and server then performance becomes sluggish. The inital binding as I have shown above is very quick. I use the same approach with the first 5000 records returned from the server and placed into an observable collection. The looping to put the records into an observable collection happens within seconds. It's very quick to loop and bind. Very efficient.
Getting the next 5,000 record from the server is fast but loading those new 5,000 records into the the observable collection (which is bound to the treeview) is slow. So, slow that the UI locks up. It appears that since the observable collection is bound to the tree view that something is causing a bottle neck. I would think that the virtualization would not care about the new 5,000 records since they are not shown.
I'm not sure where the bottle neck is here. Any examples to eleviate the problem would be appreciated.
If you need to see the example then I can send it to you. I took one of your examples in a forumn and built upon it. Basically, I get root data and bind it to the tree. Then get more root data and put it into an observable collection that is already bound to the tree already. That's the point where things get very sluggish.