After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660968 - Simplify the StTextureCache to help facilitate a merge between Mx and St.
Simplify the StTextureCache to help facilitate a merge between Mx and St.
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: st
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2011-10-05 09:11 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2011-11-18 20:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
StThemeNodeDrawing: Remove useless LoadCornerData (1.94 KB, patch)
2011-10-05 09:11 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
StTextureCache: Merge strategies (13.28 KB, patch)
2011-10-05 09:11 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
st-texture-cache: Merge strategies (13.52 KB, patch)
2011-10-19 02:26 UTC, Jasper St. Pierre (not reading bugmail)
accepted-commit_now Details | Review
st-texture-cache: Use ANSI C-style comments (4.41 KB, patch)
2011-10-19 02:27 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
st-texture-cache: Remove similar duplicated code (5.06 KB, patch)
2011-10-19 02:27 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
st-texture-cache: Rearrange code to prevent some work and a memory leak (2.70 KB, patch)
2011-10-19 02:28 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
st-texture-cache: Don't load a fallback pixbuf on the main thread (3.94 KB, patch)
2011-10-19 02:28 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
st-texture-cache: Merge strategies (13.48 KB, patch)
2011-10-19 17:44 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
st-texture-cache: Rearrange code to prevent some work and a memory leak (3.06 KB, patch)
2011-10-20 19:05 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review
st-texture-cache: Don't load a fallback pixbuf on the main thread (4.03 KB, patch)
2011-10-21 19:02 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review

Description Jasper St. Pierre (not reading bugmail) 2011-10-05 09:11:34 UTC
These should also help memory usage and other things considerably.
Comment 1 Jasper St. Pierre (not reading bugmail) 2011-10-05 09:11:36 UTC
Created attachment 198315 [details] [review]
StThemeNodeDrawing: Remove useless LoadCornerData

Done as part of my quest to merge Mx and St:

https://github.com/magcius/mx/tree/st-rebase
Comment 2 Jasper St. Pierre (not reading bugmail) 2011-10-05 09:11:39 UTC
Created attachment 198316 [details] [review]
StTextureCache: Merge strategies

Rather than have five or six structs allocated duplicating data,
just keep one and simplify the code considerably.

Again, part of my ongoing quest to merge St and Mx.
Comment 3 Colin Walters 2011-10-05 16:19:06 UTC
Review of attachment 198315 [details] [review]:

Looks fine I guess.
Comment 4 Jasper St. Pierre (not reading bugmail) 2011-10-05 16:24:59 UTC
Comment on attachment 198315 [details] [review]
StThemeNodeDrawing: Remove useless LoadCornerData

Attachment 198315 [details] pushed as f9b37a2 - StThemeNodeDrawing: Remove useless LoadCornerData
Comment 5 Colin Walters 2011-10-05 16:31:38 UTC
Review of attachment 198316 [details] [review]:

I don't understand how simplifying the code helps merging St and Mx?

This is a tricky patch and honestly I'd only like to look at this after we've branched.  There was a reason I used separate structures here but I'd have to carefully study it to remember why.  (And for future reference we should add a comment at the top of the structure defining its lifetime).
Comment 6 Jasper St. Pierre (not reading bugmail) 2011-10-05 16:38:51 UTC
(In reply to comment #5)
> Review of attachment 198316 [details] [review]:
> 
> I don't understand how simplifying the code helps merging St and Mx?
> 
> This is a tricky patch and honestly I'd only like to look at this after we've
> branched.  There was a reason I used separate structures here but I'd have to
> carefully study it to remember why.  (And for future reference we should add a
> comment at the top of the structure defining its lifetime).

The MxTextureCache is really different than the StTextureCache, so smashing them together is a lot less painful if we can simplify the code and merge some common data structures.
Comment 7 Jasper St. Pierre (not reading bugmail) 2011-10-19 02:26:51 UTC
Created attachment 199387 [details] [review]
st-texture-cache: Merge strategies

Rather than have five or six structs allocated duplicating data,
just keep one and simplify the code considerably.

Again, part of my ongoing quest to merge St and Mx.



Added a lifecycle comment.
Comment 8 Jasper St. Pierre (not reading bugmail) 2011-10-19 02:27:01 UTC
Created attachment 199388 [details] [review]
st-texture-cache: Use ANSI C-style comments
Comment 9 Jasper St. Pierre (not reading bugmail) 2011-10-19 02:27:56 UTC
Created attachment 199389 [details] [review]
st-texture-cache: Remove similar duplicated code

load_icon_pixbuf_async, load_uri_pixbuf_async, load_thumbnail_async and
load_recent_thumbnail_async is the same function four times over. Deduplicate
them, as well as cleaning them up so that they don't need to be called with
the same arguments.



This should be squashed in with the "Merge strategies" patch when committed,
I'm just keeping this separate for review clarity.
Comment 10 Jasper St. Pierre (not reading bugmail) 2011-10-19 02:28:06 UTC
Created attachment 199390 [details] [review]
st-texture-cache: Rearrange code to prevent some work and a memory leak

For some reason, the texture cache decides to make a request and then look up
an icon in the icon theme. If it's valid, it just returns, fine, but if it
doesn't add the icon, it tries to undo the request, leaking an
AsyncTextureLoadData that isn't freed in the process.
Comment 11 Jasper St. Pierre (not reading bugmail) 2011-10-19 02:28:32 UTC
Created attachment 199391 [details] [review]
st-texture-cache: Don't load a fallback pixbuf on the main thread

We create lots of random requests when searching, so this might just
help performance there.
Comment 12 Colin Walters 2011-10-19 16:35:35 UTC
Review of attachment 199388 [details] [review]:

Looks obviously right.
Comment 13 Jasper St. Pierre (not reading bugmail) 2011-10-19 16:41:15 UTC
Comment on attachment 199388 [details] [review]
st-texture-cache: Use ANSI C-style comments

Attachment 199388 [details] pushed as 5d25716 - st-texture-cache: Use ANSI C-style comments


OK.
Comment 14 Colin Walters 2011-10-19 16:56:15 UTC
Review of attachment 199387 [details] [review]:

It's not clear to me why there were originally two structures anymore, but I don't see anything wrong looking over this.  If it works for you then it's probably fine, though I'd be a bit more confident if you'd said you'd done a run through valgrind.

Just two minor comments.

::: src/st/st-texture-cache.c
@@ +340,3 @@
+
+  if (data->key)
+    g_free (data->key);

You don't need the if() here - g_free is NULL safe.

Also it'd be nice to order the _destroy calls in the same order as they're declared in the structure.

@@ +348,2 @@
+  if (data->textures)
+    g_slist_free (data->textures);

g_slist_free is also NULL safe.
Comment 15 Jasper St. Pierre (not reading bugmail) 2011-10-19 17:44:48 UTC
Created attachment 199458 [details] [review]
st-texture-cache: Merge strategies

Rather than have five or six structs allocated duplicating data,
just keep one and simplify the code considerably.

Again, part of my ongoing quest to merge St and Mx.



Rearrange the struct and free order to be a little more logical
Comment 16 Jasper St. Pierre (not reading bugmail) 2011-10-19 20:55:09 UTC
Colin, can you review the other patches? I'd like to squash them before pushing.
Comment 17 Colin Walters 2011-10-20 17:33:55 UTC
Review of attachment 199389 [details] [review]:

Looks fine.
Comment 18 Colin Walters 2011-10-20 17:36:03 UTC
Review of attachment 199390 [details] [review]:

::: src/st/st-texture-cache.c
@@ +1082,2 @@
   info = gtk_icon_theme_lookup_by_gicon (theme, icon, size, GTK_ICON_LOOKUP_USE_BUILTIN);
+  if (info == NULL)

Missing a g_free (key).  Or move the info lookup to before we calculate the key.
Comment 19 Colin Walters 2011-10-20 17:38:32 UTC
Review of attachment 199391 [details] [review]:

I think the reason we did this before is because GtkIconTheme isn't threadsafe, and looking it the code it still appears that's true.  See gtkicontheme.c:ensure_valid_themes().

So we might be able to move gtk_icon_theme_load_icon() to the worker thread, but not gtk_icon_theme_lookup_by_gicon()
Comment 20 Colin Walters 2011-10-20 17:39:13 UTC
Review of attachment 199458 [details] [review]:

If this is just a cleaned up one from before, still sounds fine.
Comment 21 Jasper St. Pierre (not reading bugmail) 2011-10-20 19:05:08 UTC
Created attachment 199569 [details] [review]
st-texture-cache: Rearrange code to prevent some work and a memory leak

For some reason, the texture cache decides to make a request and then look up
an icon in the icon theme. If it's valid, it just returns, fine, but if it
doesn't add the icon, it tries to undo the request, leaking an
AsyncTextureLoadData that isn't freed in the process.



Fixed the memory leak by moving the lookup above the key. You know what they say -- the best way to (fast|simple) code is by doing less.
Comment 22 Jasper St. Pierre (not reading bugmail) 2011-10-20 19:06:12 UTC
(In reply to comment #19)
> Review of attachment 199391 [details] [review]:
> 
> I think the reason we did this before is because GtkIconTheme isn't threadsafe,
> and looking it the code it still appears that's true.  See
> gtkicontheme.c:ensure_valid_themes().
> 
> So we might be able to move gtk_icon_theme_load_icon() to the worker thread,
> but not gtk_icon_theme_lookup_by_gicon()

I think fixing GtkIconTheme is the way to go for this one, filed bug #662319 with a patch.
Comment 23 Colin Walters 2011-10-20 19:24:21 UTC
Review of attachment 199569 [details] [review]:

Yep
Comment 24 Jasper St. Pierre (not reading bugmail) 2011-10-20 19:29:35 UTC
Attachment 199458 [details] pushed as b7bf712 - st-texture-cache: Merge strategies
Attachment 199569 [details] pushed as 0dd4584 - st-texture-cache: Rearrange code to prevent some work and a memory leak


Squashes "Remove similar duplicate code" into "Merge strategies". Leaving bug open for the last patch, "Don't load a fallback pixbuf on the main thread"
Comment 25 Jasper St. Pierre (not reading bugmail) 2011-10-21 19:02:50 UTC
Created attachment 199690 [details] [review]
st-texture-cache: Don't load a fallback pixbuf on the main thread

OK, apparently GTK+ is just considered not thread-safe, with no attempt to change this. Grab the global GDK lock before doing loading the pixbuf on another thread.
Comment 26 Owen Taylor 2011-10-21 19:08:40 UTC
Review of attachment 199690 [details] [review]:

No, this isn't right. Using gdk_threads_enter() requires _your entire program_ to follow the rules for GDK threading. See http://developer.gnome.org/gdk/stable/gdk-Threads.html

Unless (or even if) we have evidence showing that icon theme loading is a bottleneck, I don't see adapting all of mutter and gnome shell to these rules as a good idea.