GNOME Bugzilla – Bug 158991
Pango performance is not what it should be. (highly inefficient)
Last modified: 2004-12-22 21:47:04 UTC
This could be classified as a feature request as it doesn't cause a crash, just massive CPU usage. When updating any gtk widget that uses fonts at a high rate. (i.e. more than 5 times per second) there is a severe CPU penalty caused by pango rerendering things in an inefficient manner. Here's a scenario. Create GTK+ app that talks to an outside device that reads sensor reading,s which you want to display in text (GTK_label) at as high a rate as possible. IF you try to update 5 labels at 30 times/sec (we won't go into the issues if a person can actual SEE those changes, that's NOT the point) cpu usage will go to over 40% for a dual athlon 1.2 ghz box. It appears that pango recalculates the size needed, and a bunch of other things that REALLY DOES NOT need to be done OVER AND OVER. Here's a solution. When pango is called to render some font of a specific size, it should ONCE: 1. "pre-render" each glyph of the font requested to an offscreen pixmap (1 per glyph) and record dimensions (in ram) and KEEP THE GLYPHS in memory (of the xserver for speed reasons) 2. on subsequent calls to render text, just get the dimensions needed for each char from the pre stored stuff above and copy the glyphs, instead fo rendering over again from scratch. When a draw_layout call is made, it just adds up the char sizes that were previously calculated ONCE and copies over the glyphs to the destination pixmap and is basically done. This way once the initial font is rendered (only once into an offscreen pixmap) that is stored in the X server redrawing text just becomes a simple series of copies from the offscreen pixmaps for each glyph to the screen. with no rerendering necessary. Tradeoffs: more memory usage (not much if you think about it), but RAM is cheap and CPU is NOT! This method should be doable and should speedup EVERY AND ANY application that depends on pango by at least an order of magnitude or potentially much more.
caching of rendered glyphs and glyph bitmaps is done currently. See bug 135683 for a concrete patch, and bug 104683 for extensive flamage about what makes a useful bug report about performance. *** This bug has been marked as a duplicate of 104683 ***