[Change] Performance problem: MCL::setItem() is O(n^2)
Posted: Tue Mar 19, 2013 16:39
G'day All,
I'm occasionally building large multicolumn lists and have noticed a problem, that there could be a workaround for: The setItem() operation seems to be quadratic in time. See graph below. The data points are from real life usage, with n being the number of lines added (each line contains 12 items in my case), and the interpolation graph is ~ n^2. The time is in seconds. Without having done any further tests or code changes, my guess is that the culprit is the call to onListContentsChanged() which signals the list has changed, for every item added. If the signal receiver does something for all previously added items, the method ends up being quadratic in time.
![Image](http://i48.tinypic.com/2ia8mjs.png)
I was just thinking that maybe the ContentsChanged signalling should be optional, by adding a default enabled flag (so the API doesn't "break"), and that there should be provided a way for me to explicitly signal the change when my setItems are done. Would it work? Would it help?
Ideas? I could be completely wrong, of course, and it is the actual array assignment d_grid[position.row][position.column] = item; that is the problem. Anyway, I might try this soon.
/mmixLinus![Smile :)](./images/smilies/icon_smile.gif)
I'm occasionally building large multicolumn lists and have noticed a problem, that there could be a workaround for: The setItem() operation seems to be quadratic in time. See graph below. The data points are from real life usage, with n being the number of lines added (each line contains 12 items in my case), and the interpolation graph is ~ n^2. The time is in seconds. Without having done any further tests or code changes, my guess is that the culprit is the call to onListContentsChanged() which signals the list has changed, for every item added. If the signal receiver does something for all previously added items, the method ends up being quadratic in time.
![Image](http://i48.tinypic.com/2ia8mjs.png)
I was just thinking that maybe the ContentsChanged signalling should be optional, by adding a default enabled flag (so the API doesn't "break"), and that there should be provided a way for me to explicitly signal the change when my setItems are done. Would it work? Would it help?
Code: Select all
void MultiColumnList::setItem(ListboxItem* item, const MCLGridRef& position, bool bSignalChange /* = true */)
{
...
if (bSignalChange) {
// signal a change to the list contents
WindowEventArgs args(this);
onListContentsChanged(args);
}
}
Ideas? I could be completely wrong, of course, and it is the actual array assignment d_grid[position.row][position.column] = item; that is the problem. Anyway, I might try this soon.
/mmixLinus
![Smile :)](./images/smilies/icon_smile.gif)