Hello,
I'm binding a datagrid to a ICollection<Message> of custom business objects. My collection has like 20k objects.
When I bind this large collection to the grid, it takes ages to render (actually I have a timer on the DataBind() event and is taking more than 15 minutes). I have paging set to 20 items per page.
Could anyone tell me why I'm having this poor performance? Is it because of the collection size, because of the data structure used (a dictionary with smoe more methods implementing the ICollection interface)?
The rows took only like 3 secons to be retrieved from the Database.
I need to be able to show thousands of messages and I can't do it with the control, please any help would be appreciated.
Here is the code used:
log.Debug("Message Retrieval Time: " + retrievalTime.ToString()); startTime = DateTime.Now; UltraWebGridMessages.DataSource = collection; log.Debug("Binding " + collection.Count + " items"); //About 20k items UltraWebGridMessages.DataBind(); TimeSpan bindingTime = DateTime.Now - startTime; log.Debug("Message Binding Time: " + retrievalTime.ToString());
The collection is using this structure internally:
private SortedDictionary<Int64, Message> m_dictionary = new SortedDictionary<Int64, Message>();
And using these methods for the enumerators:
#region IEnumerable<Chart> Members public IEnumerator<Message> GetEnumerator() { return m_dictionary.Values.GetEnumerator(); } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return m_dictionary.Values.GetEnumerator(); } #endregion
Thanks for the help.
brafales said:My collection has like 20k objects.
This is a lot of data for WebGrid to handle all at once. It will take the grid a long time to data bind so much data.
I recommend you use partial data binding (also called "data windowing") to limit the amount of data you bind to the grid at once. In short, you retrieve only the set of rows you need from the data source, and provide those rows to the grid. As the user interacts with the grid and more data is needed, the grid retrieves the specified "window" of data.
To implement partial data binding requires you to use the grid's built-in AJAX functionality. Fortunately, this is another thing I would suggest you to implement anyway to improve performance. Turning on the grid's AJAX alone would still entail databinding to 20k items, so would not be enough on its own to make your application as responsive as it can be.