Page MenuHomePhabricator

Text Glyph Texture Release
Closed, InvalidPublic

Description

Text Glyph Texture Release.
Internally we cache glyphs texture, and we keep it even if it is not needed anymore.

We added a ref counter, for glyphs to release its resources when it is not needed anymore.

+

Add evas_glyphs_cache_release to release all cache used by glyphs (glyphs themself are not released, but there cache)

TODO:
Add global configuration options to enable or disable it

ali.alzyod triaged this task as Normal priority.

just some history - there was no ref counter before because we never referenced glyphs, strings were stored as strings (utf8) then decoded and mapped to glyph id's as they were rendered. so we refcounted whole fonts but not glyphs as we had no persistent reference. doing actual refcounting is kined of possible now with the way structs changed over time.. but it means freeing an evas text string (which has unicode glyph id's and font ptrs and positions) might get costly having to ref+++ and -- each glyph.

perhaps this might be better with something like a "every now and again" garbage cycle? so instead of a refcounter we always ++ and --, just have a used counter and used++ that counter every time we render that glyph. every now and again walk a font and all its glyphs and do used-- or used -= 100 or used -= 1000. any counter that goes <= 0 is a candidate for freeing. so rarely used glyphs get cleaned up. choosing how often to do this and the magic number for used -= N; (N might be 1, 100, 1000, ... 256, 512 ...) is a matter of some testing i guess. unused glyphs will eventually be freed anyway given enough gc cycles so it can work... rarely used glyphs ... that's a mater of weighing up the relatively frequency of use, the cost in memory, cost to re-create the glyph etc. ...so some balance here needs to be tested.

ali.alzyod added a comment.EditedMay 18 2020, 2:41 AM

just some history - there was no ref counter before because we never referenced glyphs, strings were stored as strings (utf8) then decoded and mapped to glyph id's as they were rendered. so we refcounted whole fonts but not glyphs as we had no persistent reference. doing actual refcounting is kined of possible now with the way structs changed over time.. but it means freeing an evas text string (which has unicode glyph id's and font ptrs and positions) might get costly having to ref+++ and -- each glyph.

perhaps this might be better with something like a "every now and again" garbage cycle? so instead of a refcounter we always ++ and --, just have a used counter and used++ that counter every time we render that glyph. every now and again walk a font and all its glyphs and do used-- or used -= 100 or used -= 1000. any counter that goes <= 0 is a candidate for freeing. so rarely used glyphs get cleaned up. choosing how often to do this and the magic number for used -= N; (N might be 1, 100, 1000, ... 256, 512 ...) is a matter of some testing i guess. unused glyphs will eventually be freed anyway given enough gc cycles so it can work... rarely used glyphs ... that's a mater of weighing up the relatively frequency of use, the cost in memory, cost to re-create the glyph etc. ...so some balance here needs to be tested.

Thank you for your notes,
The functions evas_font_glyph_unref, evas_font_glyph_release does not actually release glyph itself, it only releases its cache (for example texture created for this object).
Also, ref/unref happen only on text_props create/delete, not in rendering, so these calls are not called alot (much less than render cycle)

ali.alzyod updated the task description. (Show Details)May 20 2020, 3:39 AM
ali.alzyod closed this task as Invalid.Mon, Jun 15, 11:32 PM