Steve Frécinaux

What about speeding up opening documents using D-Bus?

Talking with Alex Jones on IRC this afternoon about how to speed up the opening of documents, came into our mind an idea, a hype one involving D-Bus and such ;-).

Currently, many document-related apps (Epiphany, Evince, Gedit, etc.) are actually single instances, and those who aren’t (like Gimp) probably should be. Thus, when launching the app a second time, what actually happens is that the new process sends a message to the old one, and finishes. That’s the whole point of Vytautas Liuolia’s project.

Beside, opening an application or a document currently uses the Exec entry of the application’s .deskop file, which references the application binary. So, to make it short, here is what happens when you ppen a PDF file from Nautilus:

  1. Nautilus looks in the MIME database what application should be used to show this file. Yay, it’s Evince!
  2. Looking in the .desktop entry file of Evince, the command to use is evince %u.
  3. So Nautilus runs that command, replacing %u with the actual URL of the file you want to open.
  4. The new evince process tries to register itself on D-Bus, and sees the place is already taken, so it calls a method of the existing instance.
  5. The existing instance catches the method call and opens the document.

In some ways, this is not costless: spawning a new process is not that expensive per se, but it has to initialize the Gnome libraries and such things, which are not needed in any way since the process just ends as soon as the D-Bus call is complete.

The idea, then, is to bypass the steps 3 and 4 from the above list.

How would the launch process look like after that?

  1. Nautilus looks in the MIME database what application should be used to show this file. Yay, it’s Evince!
  2. Looking in the .desktop entry file of Evince, its D-Bus object path should be /org/gnome/Evince, as the X-GNOME-DBus-App-Path key of the desktop file says.
  3. So Nautilus calls the standardized org.gnome.SingleInstanceApp.OpenFile D-Bus method on that D-Bus object.
  4. The existing instance catches the method call and opens the document. If there is no existing instance of the application, the D-Bus activation service just starts it the regular way.

If there is no X-GNOME-DBus-App-Path entry in the desktop file, then Nautilus just uses the regular way of launching apps. App launching (from panel or menus) could use as well a NewDocument-like method.

It might look like additional complexity, but in fact I don’t think it would make the developer’s life any more difficult: this can probably be written for once in Vytautas’s library, and otherwise, such methods already exist for D -Bus-enabled apps anyway, the only change would be to make those methods part of a common interface, Gnome-wide (or even desktop-wide, who knows). It also avoid the calling applications having to deal with process spawning (the D-Bus daemons handles that).

This wouldn’t mean we shouldn’t optimize the underlying libraries anymore, but I guess bypassing two steps of the launch process would always be benefical.

What are your thoughts and opinions about this? (I’ve never been good for conclusions, have I? ;-))