Improve startup time for desktop

Registered by Martin Pitt

Some components of the desktop still take very long to start (especially nautilus, gnome-panel, and compiz). Identify which parts can be optimized, to mee the 4 second budget that was set for Lucid.

In Karmic we also got a lot of new desktop components at startup (ubuntuone, desktopcouch). Check how much they contribute to the slowdown and discuss how to improve these.

Blueprint information

Status:
Complete
Approver:
Martin Pitt
Priority:
High
Drafter:
Sebastien Bacher
Direction:
Needs approval
Assignee:
Canonical Desktop Team
Definition:
Approved
Series goal:
Accepted for lucid
Implementation:
Implemented
Milestone target:
milestone icon lucid-alpha-3
Started by
Martin Pitt
Completed by
Martin Pitt

Whiteboard

Work items (package changes for speedup):
[didrocks] provide/cache-on-the-fly background image for actual resolution, to avoid downscaling; (0.5 s, reduces g-s-d's CPU by > 50%): DONE
[didrocks] in ubiquity, copy bg cache to installed system, unless /home already exists: DONE
[ted] reduce D-Bus calls in libindicate (0.2 s): DONE
[chrisccoulson] defer and nice gnome-screensaver startup (0.2 s): DONE
[chrisccoulson] fix gnome-power-manager to not trigger notify-osd on startup, only on demand: DONE
[pitti] fix gnome-settings-daemon's xsettings plugin to not spawn xrdb, but use Xlib directly (0.3 s): DONE
[pitti] do not start seahorse-daemon by default, once the linked bug is fixed (0.7 s): DONE
[pitti] fix seahorse to not block startup in autostart init phase (waiting on gconf): DONE
[pitti] make udev-acl faster by reducing unnecessary stat() and readlink() calls (0.2 s): DONE
[pitti] gnome-menus: create per-language cache file for all applications in a dpkg trigger, and change gnome-menus to read it if present (0.5 s): DONE
[pitti] brasero: change to lazy init (1 s): DONE
[pitti] stop running gnome-at-session.desktop by default, it spawns shell and gconftool just to check that it's disabled (~ 0.2 s): DONE
[pitti] stop UNE from using gnome-wm wrapper (0.3 s): DONE
[pitti] fix wncksyncdaemon to not open all *.deskop/*.mo, but use the gnome-menus cache (0.5 s): DONE
[pitti] speed up gconfd loading of its defaults (0.3 s): DONE
[pitti] fix modemmanager to not use so much CPU on init (walks entire /sys tree) (0.6 s): DONE
[pitti] streamline x11-common Xsession.d scripts: DONE
[pitti] optimize consolekit Xsession.d script: DONE
[pitti] optimize gnome-session Xsession.d script: DONE
[pitti] optimize dbus-x11 Xsession.d script: DONE
[pitti] change libnotify's notify_init() to lazy initialization, to avoid spawning notify-osd on boot: DONE
[pitti] fix nm-applet to not trigger notify-osd on startup, only on demand: DONE
[themuso] pulseaudio wrapper: should be able to go away (for autolaunch): DONE
[seb128] Replace required_components with application autostart files, to start everything at once: DONE
[seb128] investigate lot of useless stats on icon dirs in gnome-panel and nautilus and stop those from happening: DONE
[seb128] change xdg-user-dirs-gtk-update to be quicker to run (1s to 0.3s but not really impact on ressource use): DONE
[seb128] changed gnome-panel applet loading callback priority to reduce delay and extra redraw: DONE
[seb128] dropped useless gnome-settings-daemon autostart helper setting gtk1 variables: DONE
[seb128] fix nm-applet to not burn 1 to 2 seconds of CPU while connecting (caused by animation?): DONE
[bryceharrington] xorg: cache xkbcomp output: DONE
[amaranth] compiz: stop using the wrapper script: DONE
gvfs: gvfsd-trash, thumbnails the trash (not an issue on a clean install): POSTPONED
[robert-ancell] change gnome-panel to not redraw for each new applet: DROPPED
[robert-ancell] fix delay between applets loading (done in idle loop, which is busy): DROPPED
[didrocks] write a small helper program to refresh bg and trigger caching, and add it to gnome-desktop postinst: DROPPED

Work items (research, profiling):
[seb128] investigate long gnome-panel sleep periods: DONE
[seb128] investigate indicator related services startup times: DONE
[pitti] profile bluetooth-applet: DONE
[pitti] review the installed themes and try reducing the number: DONE
review the installed fonts and try reducing the number: DONE
gdm: investigate and fix delay before gdm start the xorg server: DONE
gdm: investigate why gdm doesn't pick that the xorg server is ready fast enough: DONE
[pitti] investigate what to do with the two ssh agents that we start (ssh-agent and gnome-keyring) (ssh-agent overhead is way below noise level): DONE
[pitti] investigate speedup gain of mutter patch in https://bugzilla.gnome.org/show_bug.cgi?id=607746: DONE
[pitti] profile cost of all gnome-settings-daemon plugins: DONE
[pitti] investigate impact of Xsession.d/* (below bootspeed precision, irrelevant): DONE
[seb128] profile gnome-panel: DONE
brasero: review impact on nautilus start: DONE
evince: review impact on nautilus start: DONE
file-roller: review impact on nautilus start: DONE
gksu: review impact on nautilus start: DONE
gnome-disk-utility: review impact on nautilus start: DONE
gnome-media: review impact on nautilus start: DONE
nautilus-sendto: review impact on nautilus start: DONE
nautilus-share: review impact on nautilus start: DONE
totem: review impact on nautilus start: DONE
ubuntuone-client: review impact on nautilus start: DONE
[bryceharrington] xorg: investigate moblin changes: DONE
[pitti] investigate udev-acl process between gdm and session start: DONE
gnome-panel: investigate which applets are taking time by dropping some of those: DONE
[chrisccoulson]gnome-session: investigate 1 second delay between start and activity: DONE
[seb128] investigate null_applet in une chart: DONE
[seb128] nautilus: investigate thumbnailing being done where cache should be used?: DONE
nautilus: investigate how much time is spent by plugins loading: DONE

Work items (postponed due to changing target to UNE):
compiz: split the plugins to ship all the non default options in an universe binary: POSTPONED
compiz: investigate backporting the 0.9 loader which would avoid parsing xml files on load when not required: POSTPONED
compiz: investigate building standard options statically: POSTPONED
nautilus: don't wait on gnome-panel to be loaded, start both together and send a signal to nautilus to render icons: POSTPONED
[pitti] nautilus-share: change nautilus init to lazy/backgrounded initialization: POSTPONED

Work items for ubuntu-10.04-beta-1:
[pitti] speed up or delay SMART probing in udisks: DONE
[didrocks] fix live system -> installed system background cache copying for installer-only mode: DONE
[didrocks] fix netbook-launcher-> see how to get caching when n-l draw the bg and g-s-d isn't triggered: DONE
[didrocks] provide guidance to JamieBennett to netbook-launcher-efl to get background caching: DONE
[dobey] ubuntuone-client: don't use the applet in lucid: DONE

Work items for ubuntu-10.04-beta-2:
[dobey] ubuntuone-client: defer startup of the sync daemon, and move the token check into the autostart .desktop file instead of checking within the Python daemon: DONE

also see:
https://wiki.ubuntu.com/FoundationsTeam/BootPerformance/Lucid/Desktop
https://wiki.ubuntu.com/FoundationsTeam/BootPerformance/Lucid/X

pitti, 2010-01-04: I measured the startup speed of all nautilus extensions with a cold cache on a Dell Latitude D430; sorted by descending time:
  brasero: 3.10
  share: 0.53
  evince-properties: 0.12
  gdu: 0.11
  sendto: 0.06
  seahorse: 0.04
  fileroller: 0.03
  ubuntuone: 0.01

pitti, 2010-01-13: We decided to
 - give up on compiz: we'll either use mutter in UNE, or use metacity in the OEM image
 - not work on nautilus right now, it's not an issue in UNE

seb128, 2010-01-22: I've been profiling gnome-panel and talking to robert_ancell who worked on that a bit too
- standard start time is between 6 seconds and 8 seconds, depending on the configuration (une uses less applets by default.)
- around 2 seconds are spent doing inits (libraries, icons caches, fonts caches loading and init, session registration, bonobo init, ...)
- the applets are loaded asynchronously but in idle callback which makes the action depends on the gtk main loop ability to deal with those which causes issues (robert_ancell said he would try to look at those issues)
- there is quite some layout updates and extra rendering done while applets are loaded, would be nice to delay that to after loading
- the applets themself and the gnome-panel code have no obvious slow path to work on out of those

pitti, 2010-01-24: mutter's CPU usage is negligible, and the "reduce gconf roundtrip" patch does not help (in fact, in a bootchart comparison it got a tad worse). It does not buy us anything to apply it now. (For testing, it's in my PPA)

pitti, 2010-01-25: g-s-d profile: http://people.canonical.com/~pitti/bootcharts/gnome-settings-daemon-20100125.png
 things that stand out and take long:
 - xrandr plugin (0.32 s): should be parallelized with gconf loading
 - xklavier monitor takes long, but happens in idle loop
 - background image loading takes one second in gsd, resulting in 0.8 seconds total boot time increase

pitti, 2010-01-25: investigating impact of pulseaudio:
 - with pulseaudio purged: -1.0 s (although that's probably just a side effect of mixer/sound theme etc. not starting)
 - with ubuntu-sounds purged: +1.0 s (supposedly it searches harder for the sound files?)
 - with sound theme disabled in gconf: 0

pitti, 2010-01-26: investigated impact of themes:
 - the only theme package that we could drop is gnome-themes-selected, the others are used; (UNE is currently using a mix of Dust (gtk), Human (window manager) and Humanity-Dark (icon), which needs gnome-themes-{ubuntu,selected} and human-theme.
 - Dropping gnome-themes-selected has no speed impact at all.

pitti, 2010-01-26: investigated impact of /etc/xdg/autostart, starting with none and successively re-enabling them; measured the desktop time (absolute and increase); see http://people.canonical.com/~pitti/bootcharts/autostart-impact/ for the charts
 - none (reference): 4.2 (+0)
 - the ones disabled with an AutostartCondition: 4.5 (+0.3) -> that's just noise, no additional processes
 - the ones deferred with a sleep: 4.5 (+0) -> no impact, as expected
 - essentials: g-p-m, g-s-d, nm-applet, screensaver: 8.0 (+3.5)
 - more essentials: polkit agent, xdg-userdirs: 8.0 (+0) -> change within noise range; xdg-userdirs spawns a shell, though, should be fixed
 - gnome-volume-control and pulseaudio: 8.5 (+0.5) -> pulseaudio desktop should go away (see linked bug), gvc needs profiling
 - update-notifier: 8.5 (+0) -> already defers actual operation and sleeps for a minute
 - gnome-keyring: 8.5 (+0) -> already got autospawned by nm-applet for network access
 - gdu-notification: 8.5 (+0) -> below noise level
 - bluetooth-applet: 9.0 (+0.5)

pitti, 2010-01-31: When adding a sleep 10 to the gdm upstart script, gdm immediately starts simple-slave and X (so the 1s delay between gdm-binary and simple-slave goes away), and X just takes 1 s to start up. So it's not gdm's fault. The reason for the delay is that at the time when gdm starts, there are at least three CPU-busy processes starting also: dd (from rsyslog), modem-manager, network-manager; and additionally the loadkeys/sh job from setupcon.
http://people.canonical.com/~pitti/bootcharts/daniel-lucid-20100201-deferredgdm.png
 * drop CPU intense usage of dd for rsyslog (it's reading every single character) by fixing permissions in the kernel (not requiring root privs for _reading_ from fd for /proc/kmsg) and reading /proc/kmsg from rsyslogd directly
 * do not launch modemmanager by default; preferably only launch it through an udev rule if there actually is a modem

pitti, 2010-02-02:
 * bluetooth-applet: 0.4 s, 95% of that is loading themes and icons (gtk_init() and icon_init()); would need changes in gtk (lazy loading), nothing to fix in bluetooth-applet
 * indicator-* overhead: these do not do a lot of native CPU usage, but send thousands of D-Bus messages; the number of roundtrips needs to be cut dramatically; Ted is aware of that and working on it

pitti, 2010-02-09: Dropping gnome-panel work; Robert is not available in this cycle, and this requires some intricate architectural changes, and gnome-panel will be obsolete in lucid+1 anyway.unc

pitti, 2010-02-12: moving ubuntuone improvements to beta-1; it's not enabled by default, and depends on online services team

didrocks, 2010-02-18: "write a small helper program to refresh bg and trigger caching, and add it to gnome-desktop postinst" set as DROPPED. An existing implementation exists on g-s-d (commit 61 contain the change: in http://bazaar.launchpad.net/~ubuntu-desktop/gnome-settings-daemon/ubuntu/revision/61). But there no other way than being hackish to provide that and so, revert to previous state without it at commit 62.

pitti, 2010-02-18: I moved /etc/fonts/conf.d/ away. This only brings up a ~ 0.2 s speedup, and we can't possibly remove many fonts (one of Ubuntu's basic design principles is to be able to display most languages OOTB). So nothing to be done there.

pitti, 2010-02-23: Discussed current status with Rick and Robbie in today's desktop team meeting. This is about as far as we can realistically get in lucid on the desktop side, so considering this implemented now.

(?)

Work Items

Dependency tree

* Blueprints in grey have been implemented.