We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Performance of grid sorting (SortByColumn)

Thread ID:

Created:

Updated:

Platform:

Replies:

34771 Sep 15,2005 03:08 PM UTC Nov 18,2005 09:35 PM UTC Windows Forms 2
loading
Tags: GridControl
George Mihaescu
Asked On September 15, 2005 03:08 PM UTC

Using grid version 2.1.0.9, I have strange results when performing column sorting of a fairly large grid (125 cols by 3000 rows): the speed of the sort of 2 adjacent columns is wildly different (i.e. the slowest takes 270 times more than the other!). The slow one takes about 1 minute, which is not acceptable. The columns are identical, meaning that both contain strings of comparable size. Then I''ve tried populating the slow sorting column with the same values as the fast sorting one and now the two sorted with equal speed (i.e. fast). I don'' t understand how comes that the speed of the sorting is dependent on the actual strings in the columns to the extent that one is slower than the other by a factor of 270! I will try to put together a sample, but I''m just curious if anybody had a similar experience and what was done about this.

Administrator [Syncfusion]
Replied On September 22, 2005 01:15 AM UTC

Hi George, The call to store.GetValue inside the Compare method of our default comparison method that is called from Array.Sort is a bottleneck. It is better to prepare the data in an array before calling sort. Here is some example code: GridRowCollection gridRows = this.gridControl1.Data.Rows; int headerCount = this.gridControl1.Rows.HeaderCount+1 + 1; // 1 extra for column styles info row int colnum = col + 1; // 1 extra for row styles info column int rowCount = gridRows.Count - headerCount; GridRowSortItem[] sortArray = new GridRowSortItem[rowCount]; for (int n = 0; n < rowCount; n++) { sortArray[n] = new GridRowSortItem(); GridCellCollection row = gridRows[n+headerCount]; if (row != null) { sortArray[n].row = row; GridStyleInfoStore style1 = row[colnum]; if (style1 != null) { object val1 = style1.GetValue(GridStyleInfoStore.CellValueProperty); sortArray[n].sortValue = val1; } } } Array.Sort(sortArray); //this.gridControl1.Data.SortByColumn(col, (ListSortDirection)this.gridControl1[0, col].Tag); for (int n = 0; n < rowCount; n++) { gridRows[n+headerCount] = sortArray[n].row; } public struct GridRowSortItem : IComparable { public GridCellCollection row; public object sortValue; #region IComparable Members public int CompareTo(object obj) { object val1 = sortValue; object val2 = obj != null ? ((GridRowSortItem) obj).sortValue : null; if (val1 == null && val2 == null) return 0; else if (val1 == null) return -1; else if (val2 == null) return 1; else { try { if (val1 is IComparable && val2 is IComparable) { int r = ((IComparable) val1).CompareTo(val2); //Trace.WriteLine(val1.ToString() + " / " + val2.ToString() + " : " + r.ToString()); return r; } } catch (Exception ex) { } return val1.ToString().CompareTo(val2.ToString()); } } #endregion } A project with above code is here: http://www.syncfusion.com/Support/user/uploads/MySort_43078f08.zip Stefan >Using grid version 2.1.0.9, I have strange results when performing column sorting of a fairly large grid (125 cols by 3000 rows): the speed of the sort of 2 adjacent columns is wildly different (i.e. the slowest takes 270 times more than the other!). The slow one takes about 1 minute, which is not acceptable. >The columns are identical, meaning that both contain strings of comparable size. > >Then I''ve tried populating the slow sorting column with the same values as the fast sorting one and now the two sorted with equal speed (i.e. fast). I don'' t understand how comes that the speed of the sorting is dependent on the actual strings in the columns to the extent that one is slower than the other by a factor of 270! > >I will try to put together a sample, but I''m just curious if anybody had a similar experience and what was done about this. > >

Mark Calveric
Replied On November 18, 2005 09:35 PM UTC

I''m having very simialar issues. And the oddest thing is, the string column sorts fast, and the integer column sorts slow. Im going to look into implenting the suggested fix. I''m wondering if this is what I should do, and if there is something else i should be looking into regarding sorting of integers (or decimals as well). >Using grid version 2.1.0.9, I have strange results when performing column sorting of a fairly large grid (125 cols by 3000 rows): the speed of the sort of 2 adjacent columns is wildly different (i.e. the slowest takes 270 times more than the other!). The slow one takes about 1 minute, which is not acceptable. >The columns are identical, meaning that both contain strings of comparable size. > >Then I''ve tried populating the slow sorting column with the same values as the fast sorting one and now the two sorted with equal speed (i.e. fast). I don'' t understand how comes that the speed of the sorting is dependent on the actual strings in the columns to the extent that one is slower than the other by a factor of 270! > >I will try to put together a sample, but I''m just curious if anybody had a similar experience and what was done about this. > >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;