Magos Herrera en Xalapa

Magos en Xalapa

Por primera vez Magos Herrera viene a Xalapa. Maru está organizando el evento, que será en el Teatro del Estado el sábado 3 de Mayo a las 8 PM. Date cuenta, es el sábado que viene!

Todavía hay boletos, se están vendiendo en la taquilla del teatro - 350 pesos numerado y 250 general. Parte de las ganancias van a Amigos de los Animales, A.C.

No faltes!

Update for the English-monolingual brigade: The post is about the jazz concert my wife is organizing in Xalapa this coming weekend. If you really can’t stand languages other than your own, and you have a feed reader that can filter by tags, you can filter out my posts tagged “In Spanish” and “In Norwegian”. Thank you.

It’s not a picnic table, part 2

As a followup to my previous GHashTable post, Benjamin encouraged me to time the swfdec test suite - “make check” in the tests dir is consistently 4% faster with the patch.

Also, I have patched packages for our brave openSUSE Factory users: 1-click install

It’s not a picnic table

 
Picture by Mike Bitzenhofer. License:
Because I’m just as cool as Luis.

For some time now, I’ve been considering the possibility of tightening the bolts on GHashTable, turning the idea over and over in my mind but not having had a chance to put it into practice. This can be pretty frustrating, since it’s hard for me to stop thinking about a salient idea like that without at least investing the work needed to convince myself that it’s not worth doing. It’s like an unidentified glimmer at the bottom of a lake. A silver hoard or an old bicycle? Probably the latter. But who knows?

So today I finally dove in and brought back some results.

First off, why optimize GHashTable? A hash table is a trivial data structure, so it should already be pretty optimal, right?

Let’s take a look.

As we know, any hash table will have collisions, where different keys hash to the same value. GHashTable resolves such collisions using chaining; each bucket points to the head of a linked list of elements that hash to that location. This is simple and robust, but it also has some disadvantages: One is poor locality of reference (oh, the locality!) and another is that you have to allocate and free memory, contributing to memory fragmentation over time. You also lose some memory to the extra pointers stored (one per item plus one per chain).

To improve on this, we can use open addressing: Instead of storing pointers to lists of items, we store the items in the table itself. Whenever there’s a collision, we use an algorithm to determine another suitable slot for the item, and if that slot is also occupied, we run the algorithm again until an empty slot is found. This is called probing and is obviously a more complicated business, considering that we want a) a relatively simple algorithm, b) a predictably low amount of probing and c) the ability to quickly remove items without affecting the probe sequences for other items in the table.

The simplest possible probing algorithm is called linear probing, and consists of just looking at the next slot in the table (modulo the table size) until you find what you’re looking for. Since this also has the best locality, it’s the first approach I tried. Unfortunately, due to clustering, the performance degrades too much before you reach a satisfactory load factor, even with good locality.

Quadratic probing is the next level of complexity and the one I settled with. Here, you use a quadratic polynomial to calculate the next location, which means you take bigger and bigger steps, avoiding clustering. This also affects cache performance somewhat, but considering that the few first steps are small, it’s still much better than chaining.

Since an element can be part of many probe sequences, you have to leave a special marker - commonly called a tombstone - when you remove it, so lookups don’t terminate prematurely. This isn’t a big problem, since tombstones can be reused, but you have to clean them up now and then so you don’t get too many - according to my benchmarks, this will almost never happen in GNOME apps, so shouldn’t affect performance much.

A bigger problem is that in order to guarantee that a probe will find an empty slot with load factors greater than 0.5, the table’s size has to be a power of two, which means the modulo operation will simply discard the high bits of the computed hash values. GHashTable currently uses prime-sized tables, which yields a better distribution with poor hash functions. On the other hand, taking a modulo of a power of two is a logical AND operation with a mask, which is much faster than the implied division required by prime modulos. Anyway - again, I couldn’t find any existing use cases where this caused performance problems.

Which brings me to the fact that this exercise would be meaningless without proper benchmarking. Now, I admit that due a lack of time and good tools, I haven’t been able to measure the effect on fragmentation, but it’s fairly obvious that allocating one big chunk of memory is better than one big chunk and a variable number of small chunks.

Apart from reducing fragmentation, which was my primary goal, it would be nice if speed and memory use wasn’t affected too badly. And that at least, I’ve measured.

Since synthetic tests are rarely representative, my test case was “Starting up Evolution offline with 3 gigabytes of local mail and 13 vfolders, waiting for it to finish setting up the vfolders, then quitting by closing the window with no interaction otherwise”. I measured memory use before quitting, using pmap, and total CPU time spent, using time. I realize you can’t repeat this test, it being tied to my local mail setup, but tests are rarely repeatable across computers anyway, since they have differing specs and configurations. Get the patch from the bug I filed, and run your own tests. I’d love to hear about your results!

Comparing the best out of 5 Evolution runs with old and new hash table code yielded the following numbers:

  • Time on CPU (user+sys): 956.3s, down from 1023.1s (6.5% improvement)
  • Private, writable memory: 623.5MiB, down from 645.8MiB (3.5% improvement)
  • Heap size ([heap] mapping): 310.6MiB, down from 350.0MiB (11.3% improvement)

It looks modest, but considering hash tables account for only a small part of Evolution’s resource usage, I’m rather pleased with this. It cuts memory use of most GNOME processes by a slight amount - for instance, the GNOME calculator in scientific mode gave up 140KiB of private, writable memory. You may see greater returns in apps that use Glade, because it keeps widget lookup tables around.

Home, sweet home

I’m finally back in Xalapa after more than three weeks on the road.

After the wildly successful GTK+ Berlin hackfest, I spent a day in the Hague with my good friends Andrea and Marcus, then headed for home. The flight was awful as usual, but mitigated by the fact that I was bringing back good memories and lots and lots of Belgian and Dutch candy.

Three happy hackers
Christian, Alex and Benjamin: Three happy hackers
(Ryan was AWOL for the picture)

GTK+ 2008 hackfest crew
The hackfest gang
(Picture courtesy of Tor Lillqvist)

Andrea, Marcus and their parrot, Perla
Andrea, Marcus and their pet parrot, Perla

Bikes at the Hague central station
Bikes parked at the Hague central station

Swinging by Europe: The Story Thus Far

Late last month, I strapped on my backpack and went across the ocean to FOSDEM in Brussels. It was good to see some of the openSUSE and old Ximian guys again, but I was feeling kind of drained the whole time. Had Belgian waffles w/everything, which is a lot more “everything” than it is “waffle” (i.e. ice cream, whipped cream, chocolate sauce, chocolate shavings, strawberry jam, strawberries and banana).

Old Building in Brussels
Some old building in Brussels

After FOSDEM, I spent close to two weeks in Norway, visiting family and friends in between work. I even went skiing one weekend, an experience I’ve been idealizing in my mind since I moved to Mexico. Even so, it lived up to expectations.

Ski Tracks
Ski tracks

Me and Mom Skiing
Me and my Mom skiing

My friends at Copyleft Software A/S were kind enough to lend me office space in Oslo. I must say they have an awesome work environment thing going.

Outside Copyleft’s Offices
Outside Copyleft’s offices

Lunch at Copyleft
Lunch at Copyleft

Leo is Donald Duck
Leo making his famous Donald Duck impression

After Norway, I left for Berlin where I’m currently taking up space at the GTK+ Hackfest.

End of hack week

The second Novell hack week is at an end, and I’ve set up a public Trac instance for Sterling. Development will go on there. I’ll devote some ITO (”innovation time off”) to it next time I get a chance.

Novell hack week, day 4

Four days down. How time flies when you’re having fun. I must admit that Sterling is barely past the point where it creates a panel applet that does nothing - but on the other hand, I’ve absorbed a bit of how-to on C# and Mono tools. It’s rather pleasant so far.

Apart from the panel applet business, I’ve gotten the build framework for GConf schemas, gettext, icons and UI files out of the way, so I think it’s fair to say it’s getting ready to administer kicks to the proverbial hindside. I’ll have a public Git repo up sometime tomorrow.

Sterling panel applet
Hey, it’s a start.

Novell hack week, day 3

Federico and Tambet came and hacked in addition to Mike and me. Got some stuff done, but not as much as I’d have liked to. The arrachera I had for lunch sort of knocked me out.

I’d better get some sleep now. More tomorrow.

Novell hack week, day 2

Day 2 is at an end, and I’ve spent it learning about C# and Mono tools, looking into how other projects do stuff. I now have a Git repository with a fledgling project structure, and a more solid foundation to work from knowledge-wise.

I feel a little bad for posting that Monodevelop screenshot yesterday. The intention wasn’t to make Monodevelop look bad, but rather to convey the occasional feeling of exasperation you can get when learning to use new tools, moving outside your comfort zone. I was using the older version that comes with openSUSE 10.3, assuming that would’ve been patched to fix most serious issues. I was wrong.

Fortunately, the eminent Mr. Hutchinson pointed me in the right direction - I got a newer version from one of his build service repos, and that works much better, although it still spews a little to the terminal. You can tell a lot of work went into it; this is the first time I’ve felt like I’m using a true IDE on Linux, i.e. the “integration” part actually works.

Mike arrived from Mexico City last night and will be spending the next couple of days here. His tiny new Lenovo X series Thinkpad looks totally sweet, but he spent a lot of time fighting poor wireless drivers. I guess most of us can empathize with that. Tomorrow, Tambet and Federico will hopefully join us, and we can all bask in teh hack week synergy.

Novell hack week, day 1

Novell’s hack week has started. For those of you who don’t know what a hack week is, it’s a work week where we, the programmers at Novell, get to goof around with more or less whatever project we find interesting.

I’ve chosen to start a new project called “Sterling”, the goal of which is to keep better track of my moneys. I’ve used GnuCash to do this for some time, but it’s clunky and overkill for my uses. I want to streamline the process of entering transactions and otherwise keep the complexity down, especially for people like me who know (and care) little about accounting. Indeed, I want the UI to resemble Tomboy’s in many ways:

  • Always running, with a panel applet interface.
  • Desktop-global “new transaction” hotkey.
  • Per-user database, no open/save dialogs.
  • Implicit save on edit.
  • Type-ahead completion of transaction description.
  • Suggesting details of transaction based on similar past transactions.
  • Tagging of transactions for easy cross-sectioning.
  • Simple search-as-you-type view of transaction history.
  • Multiple currencies recognized by their ISO 4217 codes.

Star Trek future features:

  • Currency conversion (use Google?).
  • Multiple registers (similar to books in Tomboy).
  • Export to XML, merge from XML.
  • Remote synchronization (by Zeroconf discovery or specific URI) allowing for shared databases.
  • Desktop search integration.
  • Drop-dead attractive graphs.

In order to make things as difficult for myself as possible, I’ve decided to learn something new and do it in C#/Mono. Of course, I’m already running into trouble…

MonoDevelop got stuck

Strange but true. I miss C, Emacs, Automake already.