wxGrid::AutoSizeColumn kills my performances

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
maxbld
Earned some good credits
Earned some good credits
Posts: 113
Joined: Wed Jan 30, 2013 10:49 pm

wxGrid::AutoSizeColumn kills my performances

Post by maxbld »

Dear all,

I've a very big wxGrid, around 50 columns and more than 2000 rows, don't ask me why that many columns, clients are crazy, right? And I also have a functionality to show/hide columns, but still there are tenth of shown columns and, in general, all could be shown together. So I was debugging the thing and found that it was spending oh so much time in a loop to auto size all the columns, becouse I've seen that wxGrid::AutoSizeColumn calls wxGridCellAttrProvider::GetAttr for every and any cell of the column. Is this a known issue?

I'm using wxGrid base class, without deriving my own wxGridTableBase, so I'd like to ask to you whether you do think it would be worth to try to do that and also set my own wxGridCellAttrProvider in it and if you know any good example for that thing.

Thank you, BR,
Max.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGrid::AutoSizeColumn kills my performances

Post by doublemax »

So I was debugging the thing and found that it was spending oh so much time in a loop to auto size all the columns, becouse I've seen that wxGrid::AutoSizeColumn calls wxGridCellAttrProvider::GetAttr for every and any cell of the column. Is this a known issue?
How else should it do it? It has to iterate over all cells to calculate the minimum size.
I'm using wxGrid base class, without deriving my own wxGridTableBase, so I'd like to ask to you whether you do think it would be worth to try to do that and also set my own wxGridCellAttrProvider in it and if you know any good example for that thing.
I don't think this will help.

I think it's better to not use wxGRID_AUTOSIZE and call wxGrid::AutoSize() manually whenever it's useful, e.g. whenever data changed or rows were added/deleted.
Use the source, Luke!
maxbld
Earned some good credits
Earned some good credits
Posts: 113
Joined: Wed Jan 30, 2013 10:49 pm

Re: wxGrid::AutoSizeColumn kills my performances

Post by maxbld »

doublemax wrote:
So I was debugging the thing and found that it was spending oh so much time in a loop to auto size all the columns, becouse I've seen that wxGrid::AutoSizeColumn calls wxGridCellAttrProvider::GetAttr for every and any cell of the column. Is this a known issue?
How else should it do it? It has to iterate over all cells to calculate the minimum size.
I was asking whether the known issue was such a slowness in getting the attributes. Is wxGrid::AutoSizeColumn already optimized? And what if I'd override wxGrid::AutoSizeColumn and use an efficient algorithm to find out the longest string, do you think I would improve its performances?
doublemax wrote:[
I'm using wxGrid base class, without deriving my own wxGridTableBase, so I'd like to ask to you whether you do think it would be worth to try to do that and also set my own wxGridCellAttrProvider in it and if you know any good example for that thing.
I don't think this will help.

I think it's better to not use wxGRID_AUTOSIZE and call wxGrid::AutoSize() manually whenever it's useful, e.g. whenever data changed or rows were added/deleted.
I'm not using wxGRID_AUTOSIZE already.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGrid::AutoSizeColumn kills my performances

Post by doublemax »

I was asking whether the known issue was such a slowness in getting the attributes. Is wxGrid::AutoSizeColumn already optimized? And what if I'd override wxGrid::AutoSizeColumn and use an efficient algorithm to find out the longest string, do you think I would improve its performances?
My guess would be that the most time is spent in wxGridCellStringRenderer::DoGetBestSize(), especially the call to wxDC::GetTextExtent(). There is definitely room for optimization there or at a higher level.
Use the source, Luke!
Post Reply