2 Mar 2005 freetype   » (Master)

FreeType & GTK/Gnome heap usage reduction

I've mostly finished optimizing FreeType memory usage when dealing with TrueType fonts, and the results are really interesting. In order to quantify the improvement, I run a fraction of the FreeType benchmark program "ftbench" to time various operations like face open/close, loading glyphs and parsing the charmap. The command itself is:

ftbench -p -b aij fontfile

heap usage was measured with FreeType's internal memory debugger, so the numbers only correspond to heap blocks allocated by the font engine.

The following are respectively the source font file, its size in bytes, and the number of heap bytes saved by the optimization:

  • vera.ttf (65,932 bytes): 53,483 bytes
  • arial.ttf (367,112 bytes): 159,016 bytes
  • times.ttf (409,280 bytes): 162,334 bytes
  • arialuni.ttf (24,131,012 bytes): 1,452,573 bytes
  • batang.ttf (15,619,828 bytes): 2,818,329 bytes

Please note that:

  • I'm comparing FreeType 2.1.9 and FreeType CVS, with memory-mapped files, which are used by default by FT2 when compiled on Unix platforms that support them.

  • The tested program loads all glyphs in a given font, and thus tends to use a lot more heap than typical GTK applications (especially when displaying CJK text). The savings displayed here are probably higher bounds, rather than averages.

  • The optimizations have only been performed on the TrueType and SFNT drivers of the font engines. This means that all other formats are probably eating too much memory. For example, the BDF driver starts by allocating a 64Kb block before reading the file. Even when the file to read is tiny. The Type 1 driver is known to be hungry as well...

I'm a bit ashamed by these numbers :o) I've tried to see if upgrading FT2 to the CVS version on my Mandrake 10.1 machine would result in any visible global memory usage reduction; Surprise, it didn't break it !! it's been unfortunately impossible to get any kind of stable numbers through 'free', 'top' and others. I suspect there is a 200-300 Kb global reduction when starting a fresh KDE 3.2 from boot (without any opened application), but that might come from something completely different. If anyone knows about a good way to measure this, I'd be extremely interested.

If you want to test it yourself on your machine, grab the latest CVS according to the following instructions. using the freetype2 module name, compiling as usual with ./configure --prefix=/usr --disable-static, then make and sudo make install. Then restart your X session. If this crashes, you can recover by following these instructions as root:

  cd /usr/lib
  rm -f libfreetype.so libfreetype.so.6
  ln -s libfreetype.so.6.XXX libfreetype.so
  ln -s libfreetype.so.6.XXX libfreetype.so.6
  restart X

Where XXX is the library minor number corresponding to the your existing installation. Mine was '7' on Mandrake 10.1, and the CVS installs '8' so just changing back the symlinks is enough to get back in a sane state.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!