RFC on lifetime of pattern_hash entries



Hi,

 

On the context of our application we use the fontconfig pango backend with a long-lived fontmap. In some cases the a text has to be laid out in an  unbounded number of different sizes (an animated SVG where the animation cycle time is co-prime with the rendering refresh rate).

 

In this cases the pattern_hash in pangofc-fontmap.c will grow without bound as entries are never removed from it until the fontmap is destroyed or clear_cache is called. As our application runs in a memory constrained embedded platform it rapidly exhausts all available memory.

 

To remedy this I have added reference counting to the entries in the pattern_hash. When the reference count drops to zero the pattern is removed from the pattern_hash (if it is still in), so the uniqueness brought by the pattern_hash is preserved but entries are removed when no longer used within the fontmap. I would appreciate if I could get some feedback on this, as per the attached patch (against pango 1.32.1).

 

I tested this under valgrind's massif tool.

 

Without the patch pango (1.32.1) consumes ever increasing amounts of memory, reaching 109 MB after the equivalent of 10 seconds of rendering at 25 fps (it would continue to increase if left running longer). The memory is actually used by fontconfig on the patterns held by pango.

 

With the patch memory consumption is constant throughout the rendering, at 18 MB.

 

Does this ref-counting approach seem reasonable?

 

Sincerely,

 

Diego

--
Diego Santa Cruz, PhD
Technology Architect
________________________________
SpinetiX S.A.
http://www.spinetix.com
________________________________

 

Attachment: hash-v2.patch
Description: hash-v2.patch



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]