Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1105
SortComparer Performance
posted

I've been tasked with doing some performance evaluation using large datasets in our application (which makes use of an ultra grid, running 10.1)

One particularly slow process I'm looking at is sorting a column that contains a sort comparer.  We use this for cases where we need to sort one column by the values in another.

In the compare method of the sortcomparer, we perform the following two calls to get the value of the column to sort by:

                        object xValue = xCell.Row.GetCellValue(_columnNameToSortBy);
                        object yValue = yCell.Row.GetCellValue(_columnNameToSortBy);

I wrapped those two calls with a timing mechanism to see how long they took and then sorted the column.

For a grid with 70,000 rows, 4 columns, those two calls combined on average took .01 milliseconds.  I also know that the Compare() method of the sorter was called 610,960 times.

So for the entire sort operation, just those two calls alone took 6109.6 milliseconds, or 6.1 seconds.  This is exacerbated by the fact that not all columns are contain sort comparers, so their sorting appears almost instantaneous compared to 6 seconds.

Here's my questions:

1) Are these numbers (albeit rough) expected metrics for this kind of operation?

2) Is there another way to access these cell values that would improve the performance? (I've also tried accessing them via xCell.Row.Cells[_columnNameToSortBy]  Even shaving .005 milliseconds off the access of the cells in the other column would cut the entire sort in half.

Thanks as always

Chris Rowland

 

Parents
  • 469350
    Offline posted

    Hi Chris,

    What happens if you sort the same column a second time? Or sort some other column first and then sort the column with the comparer?

    I can't see any reason why those two lines of code should cause any significant performance issues. It should not be any less efficient to get the value of a cell from another column as it would be to get the value of a cell from the same column being sorted. So if other columns in the grid sort quickly, there's no reason why this one should not, SortComparer or not.

    My only guess here is that you are sorting this column first, before any other column has been sorted and therefore, this sort operation just happens to be forcing the grid to create UltraGridRow objects for every row which hadn't yet been created and it is therefore the loading of the rows that is taking the time.

    If there's the case, there isn't much you can do about that.

    The code you have here is almost perfect, but there is one way you could make it a tiny bit more efficient. The GetCellValue method which takes a string has to iterate the columns collection to find the column and then it calls into GetCellValue and passes in the column.

    So you could make this a little bit more efficient by getting the Column once and passing that in instead of using a string.

    UltraGridColumn column = xCell.Band.Columns[_columnNameToSortBy];

    object xValue = xCell.Row.GetCellValue(column );
    object yValue = yCell.Row.GetCellValue(column );

    If that does not help (or doesn't help enough) see if you can put together a small sample project demonstrating the issue and we can take a look at it. Perhaps there is some way we can make the grid more efficient in this area.

Reply Children
No Data