GNOME Bugzilla – Bug 689081
No caching of icons
Last modified: 2012-11-30 10:55:41 UTC
We keep re-reading icons from the icon theme, even if we looked up them before. This is pretty bad in general, but especially so if icons are used in a list like in bug 687911. Its especially bad for symbolic icon SVGs, as these are not in the icon theme cache and re-parsed every time.
Created attachment 229899 [details] [review] Cache GtkIconInfo In order to avoid loading and keeping around the same icon multiple times we keep a cache of all outstanding GtkIconInfo objects for a given theme. We also keep alive the 32 last recently looked up infos, as most code don't keep the IconInfo object alive.
Created attachment 229900 [details] [review] Reuse rendered symbolic icons With the previous commit all loads of the same icon will share a single GtkIconInfo, which typicallty means the pixbuf is shared via Info->pixbuf. However, atm we don't share symbolic icons, which causes these to be re-read and re-parsed every time. This is especially bad if the icon is used many times in some form of list. So, we cache the last pixbuf and reuse it as long as the colors are the same.
It feels like eventually we should redo GtkIconTheme more thoroughly. Maybe that can wait until Benjamin has his css icon ideas worked out.
Its clearly grown out of scope. But, otoh, GtkIconInfo was explicitly designed in order to facilitate cacheing, thats what NautilusIconInfo was used for that got moved to Gtk+ to allow centralized caching. The nautilus icon cache keeps refs to the GtkIconInfos in its cache still. I think this patch is necessary though. As things are right now we're reading svgs from disk for every GtkImage with a symbolic icon on every state change.
Created attachment 229971 [details] [review] Cache GtkIconInfo In order to avoid loading and keeping around the same icon multiple times we keep a cache of all outstanding GtkIconInfo objects for a given theme. We also keep alive the 32 last recently looked up infos, as most code don't keep the IconInfo object alive.
Created attachment 229972 [details] [review] Reuse rendered symbolic icons With the previous commit all loads of the same icon will share a single GtkIconInfo, which typicallty means the pixbuf is shared via Info->pixbuf. However, atm we don't share symbolic icons, which causes these to be re-read and re-parsed every time. This is especially bad if the icon is used many times in some form of list. So, we cache the last pixbuf and reuse it as long as the colors are the same.
New patches, first one had some crashers.
Created attachment 230245 [details] [review] Cache GtkIconInfo In order to avoid loading and keeping around the same icon multiple times we keep a cache of all outstanding GtkIconInfo objects for a given theme. We also keep alive the 32 last recently looked up infos, as most code don't keep the IconInfo object alive.
even with these patches nautilus reloads every symbolic icon you mouse over. We need to cache all the different colored states of the symbolic icons.
Created attachment 230247 [details] [review] Cache GtkIconInfo In order to avoid loading and keeping around the same icon multiple times we keep a cache of all outstanding GtkIconInfo objects for a given theme. We also keep alive the 32 last recently looked up infos, as most code don't keep the IconInfo object alive.
Created attachment 230266 [details] [review] Cache GtkIconInfo In order to avoid loading and keeping around the same icon multiple times we keep a cache of all outstanding GtkIconInfo objects for a given theme. Additionally we return to the app not the normal pixbuf from the info, but rather a proxy copy of it sharing the same data, but no extra reference. This allows us to track when the app is no longer using the pixbuf, and we can thus ensure that the GtkIconInfo in the cache stays around for at least as long as the pixbuf is alive. When the app unrefs the pixbuf we put the Info on a short LRU list to keep it alive a bit longer, in case the app needs it in a short while.
Created attachment 230267 [details] [review] Reuse rendered symbolic icons With the previous commit all loads of the same icon will share a single GtkIconInfo, which typicallty means the pixbuf is shared via Info->pixbuf. However, atm we don't share symbolic icons, which causes these to be re-read and re-parsed every time. This is especially bad if the icon is used many times in some form of list. So, we cache the pixbufs and reuse them.
New approach, we now use a proxy object for the returned pixbuf so that we can track the lifetime of the pixbuf in the app and thus ensure the GtkIconInfo lives (and is in the cache) while the pixbuf is in use. Additionally this caches symbolic icons in all the color states, so now nautilus doesn't reaload any symbolic icons unnecessary.
Attachment 230266 [details] pushed as 92e904a - Cache GtkIconInfo Attachment 230267 [details] pushed as cfdc68d - Reuse rendered symbolic icons