Search code examples
wxpython

Grid AutoSizeColumn performance issue with large table


I have a large grid (~9400 rows x 14 columns), filled using a wx.grid.GridTableBase

After the table has been filled I perform an AutoSizeColum on all columns:

[self.grid.AutoSizeColumn(col) for col in range(self.grid.GetNumberCols())]

The issue is that specific operation takes 26 seconds (profiled with cProfile), which is unacceptable for my app'.

Are there alternative ways of doing this autosizing that would take much lower time (< 1 sec) ?


Solution

  • Solution based on AndersMunch proposal (see this link on wxpython.org)

    • sort the data of each column (with pandas for example), and keep only the longest one
    • generate the grid with this single-row data and do an AutoSizeColumns()
    • then replace by real data and regenerate the grid table and inform the grid has changed

    Costs less than 0.4 sec for my dataset, compared to the 26 sec initially.