SetReadOnly of wxGrid turns it impossibly slow

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
pvn
Earned some good credits
Earned some good credits
Posts: 105
Joined: Mon Dec 26, 2016 5:21 am
Contact:

SetReadOnly of wxGrid turns it impossibly slow

Post by pvn »

I have a wxGrid with 14 colums and 30000 rows

When I use SetReadOnly(), it becomes impossibly slow

without SetReadOnly() it takes about 1 second to print all the table (which is excellent btw)
but with SetReadOnly() it has been running for 10 minutes now :-)

Code: Select all

for (int idx_row = 0; idx_row < nbr_rows; idx_row++)
  {
    for (int idx_col = 0; idx_col < nbr_cols; idx_col++)
    {
      SetCellValue(idx_row, idx_col, "abc");
      SetReadOnly(idx_row, idx_col);
    }
  }

Is there a way to set "read_only" for all the table in another way, instead of a per cell call?
pvn
Earned some good credits
Earned some good credits
Posts: 105
Joined: Mon Dec 26, 2016 5:21 am
Contact:

Re: SetReadOnly of wxGrid turns it impossibly slow

Post by pvn »

also, the decrease in performance does not seem to be linear

for example

for 5000 rows it takes 20 seconds
for 7000 rows it takes 55 seconds

which can be explained because you are doing a linear search on all the cells everytime an attribute needs to change

Code: Select all

int wxGridCellAttrData::FindIndex(int row, int col) const
{
    size_t count = m_attrs.GetCount();
    for ( size_t n = 0; n < count; n++ )
    {
        const wxGridCellCoords& coords = m_attrs[n].coords;
        if ( (coords.GetRow() == row) && (coords.GetCol() == col) )
        {
            return n;
        }
    }

    return wxNOT_FOUND;
}
Last edited by pvn on Mon Jan 29, 2018 6:50 pm, edited 1 time in total.
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: SetReadOnly of wxGrid turns it impossibly slow

Post by coderrc »

does using wxWindowUpdateLocker
have any effect?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: SetReadOnly of wxGrid turns it impossibly slow

Post by PB »

I believe that iterating over a decently-sized wxGrid cell by cell is not a good idea.

If you can make the whole grid read only, use EnableEditing(false).

If you can make whole column read-only, try using SetColAttr() with a wxGridAttr on which you called SetReadOnly(). Similarly, if you can operate only on the row-level...

BTW, if neither of the above works, I would at least try to swap the loops, i.e., columns first and then rows. I would also try using wxWindowUpdateLocker. But I wouldn't expect much improvement....
pvn
Earned some good credits
Earned some good credits
Posts: 105
Joined: Mon Dec 26, 2016 5:21 am
Contact:

Re: SetReadOnly of wxGrid turns it impossibly slow

Post by pvn »

@codercc

wxWindowUpdateLocker had just a tiny improvement

7000 rows takes 48 seconds

but EnableEditing(false) did the job

thanks
Post Reply