RE: Major speed hacks



Hi Philip,

>-----Original Message-----
>From: tinymail-devel-list-bounces gnome org 
>[mailto:tinymail-devel-list-bounces gnome org] On Behalf Of 
>ext Philip Van Hoof
>Sent: Saturday, May 27, 2006 14:16
>To: tinymail-devel-list gnome org
>Subject: Major speed hacks
>
>I did two speed hacks today.
>
>The first is my g_list_travel_to_nth in 
>tny-msg-header-list-model.c. The idea here is simple: I 
>already know the current location. So traveling to a new 
>location can very often go much faster than each time starting 
>from zero. This significantly speeds the default sorting 
>algorithms of the GtkTreeView stack up. You'll notice speed 
>differences in seconds when sorting large folders.
>
>static GList*
>g_list_travel_to_nth (GList *list, guint cur, guint nth) {
>	if (cur == nth)
>		return list;
>
>	if (cur < nth)
>		while ((cur++ < nth) && list)
>			list = list->next;
>	else if (cur > nth)
>		while ((cur-- > nth) && list)
>			list = list->prev;
>
>	return list;
>}

Maybe some further, micro optimizations:
- G_UNLIKELY for the first 'if' might actually make sense here?
   or move it to the end of the function. Even better, the 
   caller should check and not invoke this function if cur == nth
- The third 'if ( )' can  be left out.

>The second speed hack is so simple I'm actually scared about 
>the significance. I simply replaced one g_list_append with 
>g_list_prepend in tny-msg-folder.c. And now loading huge 
>folders happens very fast.
>
>
>Enjoy the speed.

Great stuff :-)

Best wishes,
Dirk.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]