Slow sorting when column has only a few unique values

3 posts, 0 answers
  1. John
    John avatar
    16 posts
    Member since:
    Feb 2012

    Posted 31 Dec 2013 Link to this post

    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. George
    Admin
    George avatar
    500 posts

    Posted 03 Jan 2014 Link to this post

    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 >>
  3. John
    John avatar
    16 posts
    Member since:
    Feb 2012

    Posted 03 Jan 2014 Link to this post

    That fixed it, thanks!
Back to Top