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. Image for the cookie policy date

Performance issues with ResizeToFit on a large dataset

Hi,
I am using GridDataBoundGrid from syncfusion suite 4.4.x.x version.
I have about 20000 rows in a dataset with 14 columns, that I display in the grid. I need to load all of the records as per my requirement.

Without the ResizeToFit call, the grid is populated and displayed in about 2-3 seconds including getting the data from a SQL database table.

When I make a call to ResizeToFit ( anytime after the data has been assigned to Grid's datasource ) it is taking about 1 min 30 seconds for the same size of data with everything exact same.

Here is the call I make:
gridDataBoundGrid1.Model.Cols.Size.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders | GridResizeToFitOptions.NoShrinkSize);



I tried different size data and time varies depending on the size of the data.

Is this a bug in Syncfusion's call or am I doing something wrong?

Do you have any pearls of wisdom for me to speed up the performance ( alternate faster way to set the column widths based on max data )

Thanks,
Pratima




4 Replies

HA haneefm Syncfusion Team May 16, 2007 03:44 PM UTC

Hi Pratima,

The reason is that the ResizeToFit method will visit every cell in the range, and call MeasureString method to calculate the size of the cell. This will take time for large number of rows. But right now, You can speed up the process to limit the number of cells that you check. One simple way is to only resize the visible rows.

Another way would be to use something other than visiting each cell and calling MeasureString method. For example, if a column is a numeric value you could ’approximate’ the widest the cell could be by multiplying the max digits times the average character width for the font. This would just be a quick calculation without having to visit every cell. Or, if you know the maximum number of characters in a field of your database, you could set its width based on the max number of characters and the average character width. So, instead of calling ResizeToFit (and having it visit every cell), you would just call some calculation that would approximate the needed width.

This would be the only way to speed things up significantly now.

Best regards,
Haneef


SK Sumeet Koshal June 19, 2007 04:43 AM UTC

Hi Haneef,

Can you please provide me some sample for this(only resize the visible rows)?

Regards
Sumeet

>Hi Pratima,

The reason is that the ResizeToFit method will visit every cell in the range, and call MeasureString method to calculate the size of the cell. This will take time for large number of rows. But right now, You can speed up the process to limit the number of cells that you check. One simple way is to only resize the visible rows.

Another way would be to use something other than visiting each cell and calling MeasureString method. For example, if a column is a numeric value you could ’approximate’ the widest the cell could be by multiplying the max digits times the average character width for the font. This would just be a quick calculation without having to visit every cell. Or, if you know the maximum number of characters in a field of your database, you could set its width based on the max number of characters and the average character width. So, instead of calling ResizeToFit (and having it visit every cell), you would just call some calculation that would approximate the needed width.

This would be the only way to speed things up significantly now.

Best regards,
Haneef


SK Sumeet Koshal June 19, 2007 09:52 AM UTC

Haneef.

I am able to do this. so, no need to send me any sample.

Thanks
Sumeet

>Hi Haneef,

Can you please provide me some sample for this(only resize the visible rows)?

Regards
Sumeet

>Hi Pratima,

The reason is that the ResizeToFit method will visit every cell in the range, and call MeasureString method to calculate the size of the cell. This will take time for large number of rows. But right now, You can speed up the process to limit the number of cells that you check. One simple way is to only resize the visible rows.

Another way would be to use something other than visiting each cell and calling MeasureString method. For example, if a column is a numeric value you could ’approximate’ the widest the cell could be by multiplying the max digits times the average character width for the font. This would just be a quick calculation without having to visit every cell. Or, if you know the maximum number of characters in a field of your database, you could set its width based on the max number of characters and the average character width. So, instead of calling ResizeToFit (and having it visit every cell), you would just call some calculation that would approximate the needed width.

This would be the only way to speed things up significantly now.

Best regards,
Haneef


HA haneefm Syncfusion Team June 19, 2007 05:43 PM UTC

Hi Sumeet,

You could try doing it on demand in TopRowChanged. There you could size just the visible rows, (ViewLayout.VisibleCellsRange). This way you could size things a little at the time on demand when new rows are exposed.

[c#]
private void gridDataBoundGrid1_TopRowChanged(object sender, GridRowColIndexChangedEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
grid.Model.RowHeights.ResizeToFit(grid.ViewLayout.VisibleCellsRange);
}

GDBGResizeToFit.zip

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon