[cairo] Reducing CPU usage in News Ticker Implementation

Chris Wilson chris at chris-wilson.co.uk
Fri Aug 31 13:17:40 PDT 2007

Darwin Bautista (djclue917 at gmail.com) said: 
> I just want to know if there's a more efficient way of implementing a
> news ticker. Currently, I'm using my own "Cairo-fied" version of the
> ticker widget used in pyt!ck (
> http://whatah.nyunderground.net/code/pytick/ ).
As pointed out, caching the layout in a surface pattern is the standard
response to such speed issues.

> The problem is that
> the ticker consumes a lot of CPU when the Pango layout is relatively
> big (377 character-long text, DejaVu Serif Semi-Condensed 40) since X
> performs a lot of redrawing every second (e.g., 50 redraws/second if
> the scroll timeout is set to 20ms).

The question arises as to identify the bottleneck and is it worth
fixing. In this case, the issue appears to be that we are causing X to
render glyphs that will never reach the widget. On the Cairo side we
have a few opportunities to cull glyphs that will never be visible. As a
demonstration, the attached patch culls the glyphs before adding them to
the Xlib glyph stream - as it appears to be the easiest place to perform
the culling.

Applying this patch causes the CPU usage to become negligible, a drop
from 20% on my machine. (I've also attached the updated ticker.py that I
was running as my benchmark.) However, it remains to be seen whether it
brings sufficient benefit across the desktop to justify its overhead.
Chris Wilson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glyph-cull.patch
Type: text/x-diff
Size: 3197 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20070831/e0675cf0/attachment-0001.patch 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ticker.py
Type: text/x-python
Size: 4864 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20070831/e0675cf0/attachment-0001.py 

More information about the cairo mailing list