Taciturn

All entries (archive)

I was hacking together a GTK-based program that had to be capable of displaying a long list of items. It was running quite slowly — taking 174 seconds to load 50 000 items. That seemed like way too long for what should be one malloc per item and adjusting a few pointers.

The structure I used was a GtkTreeStore. It turns out it's ridiculously inefficient at appending items. Prepending takes about as long as you'd expect — about 0.83 seconds.

I tried another test with 280 000 lines. That took 4.25 seconds using gtk_tree_store_prepend, and I killed the process after nearly 30 minutes when it was using gtk_tree_store_append.

The slowness looks like it is in the GtkTreeStore's GNode backend where appending an item at a particular level involves walking the list of every item on that level:

while (sibling->next)
  sibling = sibling->next;

So, if you're building a GtkTreeStore with sequential data, reverse your data and use gtk_tree_store_prepend rather than gtk_tree_store_append — it's much faster.

I also tested GtkListStore and appending is as fast as prepending.

Tested with GTK 2.12.1 and Glib 2.14.1 (Debian). Source.

Comments

There are no comments on this entry.

Post comment


Also available in RSS.