This is a migrated thread and some comments may be shown as answers.

Slow sorting when column has only a few unique values

2 Answers 121 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 31 Dec 2013, 09:37 PM
I have a GridView with around 6k rows in it.  When I click the column header to sort the rows, some columns are fast (a second or two) and some are very slow (45 seconds or so).  it looks like the difference is that the slow ones only have a tiny number of distinct values in them.  For example my "Name" column is mostly unique per row, and it sorts in a couple second, but my "Excluded" column only shows "No" or "Yes" (about 98% "No" and 2% "Yes") and it takes 45 seconds to sort by. 

It looks like the problem is that your sort algorithm does not deal with this problem scenario well due to almost all the items being identical.  My profiler shows that with the Name column most of the time from HybridIndex.PerformQuickSort is in List.BinarySearch and that GridViewRowInfoComparer.Compare only gets called about 100k times.  But with the "Excluded" column most of the time is in GridViewRowInfoComparer.Compare which is called a whopping 17M times.

I don't think this data scenario is uncommon, so I think there should be some way to handle this.  If I could tell this column to use a different sort algorithm that would be fine. 

2 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 03 Jan 2014, 03:07 PM
Hi John,

Thank you for writing.

You can change the threshold which determines which algorithm will be used when sorting. You can use the following code:
RadDataView<GridViewRowInfo> dataView = this.grid.GridViewElement.Template.ListSource.CollectionView as RadDataView<GridViewRowInfo>;
FieldInfo indexerField = typeof(RadDataView<GridViewRowInfo>).GetField("indexer", BindingFlags.NonPublic | BindingFlags.Instance);
HybridIndex<GridViewRowInfo> indexer = indexerField.GetValue(dataView) as HybridIndex<GridViewRowInfo>;
indexer.Threshold = 500;

This will make the grid use a Red-Black Tree if the count of the items is greater than 500.

I hope this helps.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
John
Top achievements
Rank 1
answered on 03 Jan 2014, 04:39 PM
That fixed it, thanks!
Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
George
Telerik team
John
Top achievements
Rank 1
Share this question
or