Archive for May, 2006

Optimisation by killing O(n^2) algorithms

Monday, May 29th, 2006

Sometimes optimising means shaving milliseconds after spending lots of time on subtle algorithms… And sometimes it just means discovering huge counter-performant parts in your fast mail user agent. The advantage of the latter is that, for similar amounts of work, you get much more results.

O(n^2) algorithms are algorithms which execution time is proportional to the square of the number of elements to be processed. Meanwhile, O(N) algos are directly proportional to the number of elements, and O(1) is as fast given any number of elements. Every hacker would love to see only O(1) algorithms everywhere, but failing that, none of them like O(n^2). You can read more about this on Wikipedia.
Recently that’s what I’ve been doing on Sylpheed-Claws. Investigating why Claws can take huge amounts of time doing normal stuff has proven to be interesting work with a nice reward, just using tools like gprof, callgrind and gdb.

(results are at the end)

Symptom: Sylpheed-Claws takes too much time to open a folder
Fix: GtkCTree’s sorting functions uses gtk_ctree_link and gtk_ctree_unlink to build the tree, and these functions uselessly (in this case) use g_list_position on the rows list. Which means that building a 10k mail tree calls g_list_position 10000 times, which walks the whole list using a loop that runs for 1, then 2, then… then 10000 iterations. Reimplement gtk_ctree_insert_gnode and their called static functions.

Symptom: “Mark all read” and other mass flag changes takes too much time in current folder
Fix: Disconnect the GUI message update callback during flags unsetting, and update all at once instead of 10000 times.

Symptom: Copy and Move takes too much time
Fix: Use g_slist_prepend instead of g_slist_append to build the list of mails to copy/move, and save 10000 complete walks of the list.In addition to that, don’t take the pain of fetching and parsing the whole messages if this isn’t necessary. Finally, implement a progress bar for the psychological value of not facing a frozen app.
Symptom: Deleting or moving mails is slow
Fix: Before executing a move or deletion, we have to unthread the mail list, because removing a node removes its children even if they aren’t planned to be moved/deleted. Instead of unthreading everything recursively, just unthread child nodes of deleted/moved mails if they, themselves aren’t planned to be deleted/moved.

Symptom: Shift-selecting thousands of mails is slow
Fix: shift-selection is done by calling the select function N times with the ‘range’ mode, and add the rows using gtk_clist_select_row(). This function performs a g_list_nth() on the rows list to figure the node from the position, which makes it an O(n^2) algorithm. Replace that by getting the node once for the lower bound of the selection, and selecting the rest of the rows manually, just shifting in the rows list.

Symptom: Unselecting tons of mails is slow
Fix: freeze/thaw the list before unselecting everything, and avoid N repaints and check for repaints.

End result:
wwp has been kind enough to compare timings between 2.2.0 and latest CVS. He used a really big folder, 80000 messages, and his results are astonishing:

system: FC5 on a D810 laptop, P4 2GHz, 1GB, SATA 80GB ext3 (no noatime) 5400rpm/sec (32MB/sec), gtk+ 2.8.17 glib 2.10.2
folder: 80000 messages, all read and no specific flag, mostly threads (mailing-lists)
  2.2.0 2.2.0cvs61
   
enter (threaded)*: 3min54sec (3min4sec) 8sec
turn off threads: 7sec 5sec
turn on threads*: 3min49sec (3min) 7sec
select all (shift+click): 4min4sec 1sec
mark all unread: 9min20sec 4sec
mark all unread again: 8min30 2sec
select all (ctrl+a): 1sec 1sec
mark read: 18min 3sec
move**: more than 70min 1min15sec(7sec)
copy**: more than I can afford! 2min15sec(1min30sec)
delete: 43min 19sec
*total-time(sorting time)
**total-time(copy/move time, the rest being cache update)

These results are almost embarrassing. But like all O(n^2) algorithms, operation on common sizes of folders,0-5000 mails, was fast enough. The bigger the folder, the bigger the gain!

Biloba dans la presse!

Wednesday, May 17th, 2006

J’ai eu aujourd’hui la surprise (et la joie) de voir mentionné Biloba, le jeu de Guillaume Demougeot, dans une demi-page du Linux Pratique n°35 !

L'article

Sympathique !

Dotsrc.org rocks

Tuesday, May 16th, 2006

Finally fed up with SF.net’s multiple downtimes and “hardware problems” that brought down anoncvs for a month, dev cvs for a week, and mailing-list lagging for multiples days without even an announcement… We moved CVS and mailing-lists to dotsrc.org.

The change went really smoothly, apart a little glitch, where I forgot to manually remove the subscribers from the new mailing lists when they had ‘nomail’ set on.

Apart from that, the nice guys at dotsrc.org seem to do a wonderful job, and it really makes a refreshing change. So, thanks guys !

You can see updated info about CVS and the mailing-lists on our website.

What’s happening to Sylpheed (Main)?

Wednesday, May 3rd, 2006

Although we don’t sync from Sylpheed anymore, we still check its progress in case a bugfix could apply to us…

But, strangely, nothing seems to happen on Sylpheed since more than one month. Hiroyuki left #sylpheed in early April, posted only one or two messages on his mailing-list,  and the last line in Sylpheed’s ChangeLog is:

2006-03-29

* version 2.2.4

Strange.

Impatient

Wednesday, May 3rd, 2006

I’m quite impatient to get the next release(s) out of the door… There will be, very soon, both 2.2.0 and 2.1.2 releases… While 2.1.2 will be rather “unsexy” as a bugfix release, it should be the most stable of 2.1.x branch, adapted to people not wanting the new features.

Concerning 2.2.0, we’ll have a few nice things to present you, especially an IMAP on steroids, a system to help sysadmins deploy Sylpheed-Claws on a large scale, and other goodies… With all of 2.1.2’s bugfixes, of course.

Meanwhile, our bugzilla’s open bug count is lower than ever, with 15 bugs open, 12 of them being enhancements requests… Nice !

news for few, stuff no-one cares about