Filling GtkTreeView ... fast

Submitted by Frederic Marand on

GtkListStore performance A discussion these days on the PHP-GTK general mailing list revolved around the issue of feeding a large amount of rows to the model bound to a GtkTreeView.

Marc Quinton pasted a sample built to demonstrate the performance gain obtained by disconnecting the GtkListStore from the GtkTreeView while filling the list with data, just like one would wrap such fills in a EnableControls / DisableControls pair in Delphi.

Hard numbers

Surprisingly enough, he had to conclude the difference was not very significant, which seems rather counter-intuitive, so I thought I'd dig a bit deeper, and here are the data. The graph representing them is the one at the top of this post (click for larger graph).

Numbers are expressed in rows per millisecond
Rows Fill while connected Fill disconnected then reconnect
First pass Next passes First pass Next passes
2000 21,5 13,3 27,0 23,0
5000 20,0 12,5 26,3 21,7
10000 20,0 12.5 25,6 21,7
20000 20,0 12,5 25,6 21,7
50000 20,0 12,5 26,3 21,7
100000 20,0 11,2 24,4 21,3
500000 19,2 10,2 25,0 20,0

Results compiled on a 2.8 GHz P4, 1 GB RAM, XP SP1.

Side notes

Whatever option is chosen, the first pass of filling the list is always the fastest, presumably because it does not involve freeing the previous list first.

When choosing the "always connected" option, once the delay spent filling the list has been expanded, there still remains a delay for the GtkTreeView itself to catch up visually. With the larger lists, this becomes costly too: with the 500k rows list taking 26 (first pass) or 49 (next passes) seconds to fill, the view still requires 29 more seconds to redisplay.

On the other hand, when filling the list in disconnected mode and reconnecting once the list is filled, the view answers fluidly, with no perceptible delay, giving this option a much higher edge over the simpler solution of staying connected than the raw numbers might suggest.

It looks like this technique should go into a "PHP-GTK Best practices" somewhere.