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 674118 - application-window: Desktop file handling improvements
application-window: Desktop file handling improvements
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkApplication
3.4.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-04-14 22:22 UTC by Kalev Lember
Modified: 2012-04-16 16:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
application-window: Move desktop file handling code to separate function (3.19 KB, patch)
2012-04-14 22:23 UTC, Kalev Lember
committed Details | Review
application-window: Try harder to look up the application name (2.27 KB, patch)
2012-04-14 22:23 UTC, Kalev Lember
none Details | Review

Description Kalev Lember 2012-04-14 22:22:33 UTC
The desktop file handling code that was added in bug #673882 fails to get the app's name when the desktop file name doesn't match the executable name. My test case is the lightsoff game with gnome-lightsoff.desktop, as packaged in Fedora.

A possible way to fix this would be to read in all desktop files and find which one of them references the executable name.
Comment 1 Kalev Lember 2012-04-14 22:23:13 UTC
Created attachment 212064 [details] [review]
application-window: Move desktop file handling code to separate function
Comment 2 Kalev Lember 2012-04-14 22:23:26 UTC
Created attachment 212065 [details] [review]
application-window: Try harder to look up the application name

Application names don't always match with .desktop file names, so we
need to do more work to find the correct desktop file.
Comment 3 Kalev Lember 2012-04-14 22:27:00 UTC
Review of attachment 212065 [details] [review]:

It would be very easy to get rid of all the #ifdef HAVE_GIO_UNIX code, but that would remove the optimization which currently tries to read in ${executable_name}.desktop and if that fails, falls back to g_app_info_get_all(). I don't really know how to measure g_app_info_get_all() penalty for app startup speed, so I left the HAVE_GIO_UNIX code in for now.
Comment 4 Emmanuele Bassi (:ebassi) 2012-04-15 08:10:17 UTC
(In reply to comment #0)

> A possible way to fix this would be to read in all desktop files and find which
> one of them references the executable name.

this is not a good plan at all; considering that there is no cache of desktop files to mmap at startup, this would imply hitting the disk multiple times, which will lead to a loss of performance.

what I'm interested in is why Fedora changes the names of desktop files; either they stop doing that, or they submit their patch upstream.

(In reply to comment #3)
> Review of attachment 212065 [details] [review]:
> 
> It would be very easy to get rid of all the #ifdef HAVE_GIO_UNIX code, but that
> would remove the optimization which currently tries to read in
> ${executable_name}.desktop and if that fails, falls back to
> g_app_info_get_all(). I don't really know how to measure g_app_info_get_all()
> penalty for app startup speed, so I left the HAVE_GIO_UNIX code in for now.

it's easy to measure the penaly: just time the startup of an application that matches, and then time the startup of an application that does not match - once without your patch, and once with it. repeat about 10 times to get some stable numbers. blowing the kernel inode caches would also allow you to identify the timing in cold start cases.
Comment 5 Kalev Lember 2012-04-15 11:52:57 UTC
Did some testing and with both patches applied, measured the time it takes to execute gtk_application_window_get_app_desktop_name().

hot cache and matching desktop file name (lightsoff.desktop):
0.0003s

hot cache and non-matching desktop file name (gnome-lightsoff.desktop):
0.0311s

cold cache and matching desktop file name (lightsoff.desktop):
0.0022s

cold cache and non-matching desktop file name (gnome-lightsoff.desktop):
1.4789s


I think this shows that it's certainly worth keeping the ${executable_name}.desktop file reading optimization. Where I am unsure is whether it's worth trying to fall back to parsing all the desktop files when:
 - the app doesn't have a name set with g_set_application_name(), and
 - the app doesn't have a matching ${executable_name}.desktop file

--------------------------

Test setup:

11 test runs, dropped first result and calculated the average of the 10 remaining results. For cold cache tests ran "sync && echo 3 > /proc/sys/vm/drop_caches" before doing the test.

The disk used for /usr/share is rotating media.
Comment 6 Matthias Clasen 2012-04-16 12:26:53 UTC
(In reply to comment #4)

> 
> what I'm interested in is why Fedora changes the names of desktop files; either
> they stop doing that, or they submit their patch upstream.
> 

Mostly historical baggage. The desktop entry spec has this misfeature of 'vendor prefixes', and back in the day, that was thought to be a good idea to apply. Now, desktop file names tend to spread out into all sorts of configuration, so once you've applied such a prefix, you're kinda stuck, unless you are willing to break user configuration.
Comment 7 Cosimo Cecchi 2012-04-16 15:49:59 UTC
Review of attachment 212064 [details] [review]:

I think this makes sense, but I have a comment on the code below.

::: gtk/gtkapplicationwindow.c
@@ +322,3 @@
+                  /* get the name from .desktop file */
+                  name = gtk_application_window_get_app_desktop_name ();
+                  if (name == NULL)

You're losing the if (g_strcmp0(app_name, name) == 0) condition here, in which case we still want to show Application
Comment 8 Kalev Lember 2012-04-16 16:10:27 UTC
Thanks Cosimoc.

(In reply to comment #7)
> You're losing the if (g_strcmp0(app_name, name) == 0) condition here, in which
> case we still want to show Application

Hm. The way I read this condition is: if the app's executable name matches the name set in .desktop file, show Application. This seems strange; why would we want to show the fallback name (Application) if these two happen to match?
Comment 9 Cosimo Cecchi 2012-04-16 16:16:20 UTC
(In reply to comment #8)
 
> Hm. The way I read this condition is: if the app's executable name matches the
> name set in .desktop file, show Application. This seems strange; why would we
> want to show the fallback name (Application) if these two happen to match?

You're right, makes sense; I didn't realize the fallback in GIO for when a missing name is "Unnamed". Feel free to push the patch to the master and gtk-3-4 branches.
Comment 10 Emmanuele Bassi (:ebassi) 2012-04-16 16:26:05 UTC
(In reply to comment #9)
> (In reply to comment #8)
> 
> > Hm. The way I read this condition is: if the app's executable name matches the
> > name set in .desktop file, show Application. This seems strange; why would we
> > want to show the fallback name (Application) if these two happen to match?
> 
> You're right, makes sense; I didn't realize the fallback in GIO for when a
> missing name is "Unnamed". Feel free to push the patch to the master and
> gtk-3-4 branches.

really? this still means that, with a cold cache, creating a new application will take 1 second more in case the name does not match. I'm not entirely comfortable with a speed regression of this size.
Comment 11 Emmanuele Bassi (:ebassi) 2012-04-16 16:27:13 UTC
sorry, the first patch looks okay to me; it's the second patch that I don't really like.
Comment 12 Kalev Lember 2012-04-16 16:27:49 UTC
Review of attachment 212064 [details] [review]:

Thanks, pushed to both master and gtk-3-4 branches.
Comment 13 Kalev Lember 2012-04-16 16:37:20 UTC
(In reply to comment #11)
> sorry, the first patch looks okay to me; it's the second patch that I don't
> really like.

Yes, I think I agree that the second patch is a bad idea.

I'd like to additionally point out that the startup penalty would also happen not only when the names don't match, but also when an app doesn't have a desktop file at all. Which might be even worse.

So the first patch is committed and I'm dropping the second one; I'll take a look if we can rename the desktop files back in Fedora instead.

Thanks everybody!