Warning: |
GNOME Goal: Use g_timeout_add_seconds instead g_timeout_add
Summary
From http://gould.cx/ted/blog/Saving_the_world_one__w_at_a_time and https://wiki.ubuntu.com/SavingTheWorld
One of the features of Glib is that it provides two timeout functions: g_timeout_add and g_timeout_add_seconds. The difference is much more important than not having to add a "* 1000" in one and not the other. The important thing that the second function does is that it tried to group wake-ups to ensure that the program wakes up as little as possible. This is never perfect, but it's a small thing that can help to save some power and reduce the number of wake-ups.
Guidelines
So if you'd like to help save a little power on your machine, follow these instructions.
Take one of the packages in the Gnome git repository: http://git.gnome.org
$ git clone git://git.gnome.org/<package>
- Branch it to work on your local branch:
$ git checkout -b <new_branch>
- Find the instances that might be causing the problem.
$ git grep "timeout_add "
Replace g_timeout_add for g_timeout_add_seconds ( see the comments below )
Commit and generates the Changelog: (for the Changelog format see http://live.gnome.org/Git/CommitMessages)
$ git commit -a
- Generate a patch:
$ git format-patch HEAD~1
Submit a bug report with the patch to http://bugs.gnome.org/
Comments before approval
Add your comments to this goal proposal here |
PaoloBorelli: the instructions should make clear that the goal is not about finding all instances of g_timeout_add and blindly replacing them: only in some cases the function should be replaced with the add_seconds variant otherwise we would have simply fixed the g_timeout_add implementation. In particular the candidates for beeing replaced are timeouts called in a recurrent manner (eg polling) and that do not need an accurate timeout. Timeouts that are fired just once or that result in something visible to the user should usually not be changed. Obviusly things need to be evaluated case by case.
Comments from Emmanuele Bassi in bug #581258 (comment #4):
timeout_add_seconds() is meant to be used to cause the minimum amount of wakeups and let the kernel coalesce multiple wakeups at the same time. this means that a 5 seconds timeout might actually occur at the (worst case scenario) 7 seconds marker, if other timeouts are scheduled for that delay.
I'd agree with Paolo that timeouts that are invoked just once do not pose a significant difference, but I'd love to get an informed opinion from the kernel people.
Comments from HavocPennington in bug #573718 (comment #6):
"I think add_seconds should be used when:
- The timeout is at least 1 second (and can be a round number of seconds)
- The timeout is recurring i.e. happens over and over in the background
If the timeout callback returns TRUE that keeps the timeout installed; if FALSE that removes the timeout. So if a timeout returns FALSE, usually it is not a recurring timeout."
Status of this goal
Note: Updated automatical stats can be found at http://www.gnome.org/~fpeters/reports/g_timeout_add.html
Tip: If you choose to work on a module, create the bug report on the GNOME bugzilla. This way people will know someone already works on it, and won't duplicate the work you're doing. |
State |
Markup |
todo |
<: #ff8080> todo |
patch |
<: #ffc849> [[GnomeBug:xxxxx|patch]] |
done |
<: #80ff80> [[GnomeBug:xxxxx|done]] |
not needed |
<: #80ff80> not needed |
Above are the states and corresponding markup to update the modules state table below.
Tarball |
Status |
|
Desktop |
||
alacarte |
not needed |
|
brasero |
||
bug-buddy |
not needed |
|
not needed |
||
dasher |
not needed |
|
done |
||
not needed |
||
not needed |
||
not needed |
||
evolution-data-server |
||
evolution-mapi |
to do |
|
evolution-webcal |
not needed |
|
file-roller |
to do |
|
gcalctool |
not needed |
|
gconf-editor |
not needed |
|
gnome-backgrounds |
not needed |
|
gnome-control-center |
||
gnome-desktop |
not needed |
|
gnome-desktop-sharp |
not needed |
|
not needed |
||
gnome-icon-theme |
not needed |
|
gnome-keyring |
||
gnome-netstatus |
to do |
|
gnome-nettool |
to do |
|
gnome-mag |
to do |
|
gnome-menus |
not needed |
|
gnome-power-manager |
||
gnome-python-desktop |
not needed |
|
gnome-session |
||
gnome-settings-daemon |
||
gnome-sharp |
not needed |
|
gnome-system-monitor |
||
to do |
||
gnome-terminal |
not needed |
|
not needed |
||
gnome-user-docs |
not needed |
|
gnome-user-share |
to do |
|
not needed |
||
gst-plugins-base |
||
gst-plugins-good |
||
to do |
||
gtkhtml |
to do |
|
done |
||
gvfs |
||
hamster-applet |
not needed |
|
libgail-gnome |
not needed |
|
libgnomekbd |
to do |
|
libgtop |
not needed |
|
not needed |
||
liboobs |
not needed |
|
librsvg |
not needed |
|
not needed |
||
libwnck |
||
metacity |
||
mousetweaks |
to do |
|
orca |
not needed |
|
pygtksourceview |
not needed |
|
to do |
||
swfdec-gnome |
not needed |
|
tomboy |
not needed |
|
totem-pl-parser |
not needed |
|
vinagre |
done |
|
vino |
||
vte |
to do |
|
done |
||
Desktop (to be deprecated) |
||
libgnomeprint |
to do |
|
libgnomeprintui |
to do |
|
Platform |
||
GConf |
||
at-spi |
not needed |
|
atk |
not needed |
|
glib |
||
gtk-doc |
not needed |
|
pango |
not needed |
|
Platform (to be deprecated) |
||
ORBit2 |
to do |
|
audiofile |
to do |
|
esound |
to do |
|
gnome-mime-data |
to do |
|
gnome-vfs |
to do |
|
gnome-vfs-monikers |
to do |
|
libIDL |
to do |
|
libart_lgpl |
to do |
|
libbonobo |
to do |
|
libbonoboui |
to do |
|
libglade |
not needed |
|
libgnome |
to do |
|
libgnomecanvas |
to do |
|
libgnomeui |
to do |
|
Admin |
||
not needed |
||
sabayon |
||
Development Tools |
||
accerciser |
not needed |
|
anjuta |
||
devhelp |
not needed |
|
gdl |
not needed |
|
glade3 |
||
gnome-devel-docs |
to do |
|
Bindings (C++) |
||
glibmm |
to do |
|
pangomm |
not needed |
|
gtkmm |
not needed |
|
libglademm |
not needed |
|
gconfmm |
not needed |
|
libgnomecanvasmm |
to do |
|
libgnome-vfsmm |
to do |
|
libgnomemm |
to do |
|
libgnomeuimm |
to do |
|
libxml++ |
not needed |
|
Bindings (java) |
||
glib-java (jg-common) |
to do |
|
libgtk-java |
to do |
|
libgnome-java |
to do |
|
libgconf-java |
to do |
|
libglade-java |
to do |
|
Bindings (mono) |
||
gtk-sharp |
not needed |
|
Bindings (perl) |
||
Glib |
to do |
|
Gtk2 |
to do |
|
Gtk2-GladeXML |
to do |
|
Gnome2-GConf |
to do |
|
Gnome2-Canvas |
to do |
|
Gnome2-VFS |
to do |
|
Gnome2 |
to do |
|
Bindings (python) |
||
pygobject |
not needed |
|
not needed |
||
pyorbit |
not needed |
|
not needed |
||
Mobile |
||
GConf (dbus-based) |
to do |
|
evolution-data-server (dbus-based) |
to do |
|
clutter-gst |
to do |
|
External Dependencies |
||
avahi |
to do |
|
cairo |
not needed |
|
cairomm |
not needed |
|
clutter |
to do |
|
clutter-cairo |
to do |
|
clutter-gtk |
to do |
|
conduit |
to do |
|
dbus |
to do |
|
dbus-glib |
to do |
|
dbus-python |
done |
all test/example code |
desktop-file-utils |
not needed |
|
Devicekit-power |
to do |
|
enchant |
not needed |
|
expat |
to do |
|
farsight2 |
to do |
|
fontconfig |
not needed |
|
gamin |
to do |
|
gnutls |
not needed |
|
gpgme |
to do |
|
gtk-vnc |
to do |
|
hal |
to do |
|
hicolor-icon-theme |
not needed |
|
icon-naming-utils |
not needed |
|
intltool |
not needed |
|
iso-codes |
not needed |
|
libcanberra |
not needed |
|
libcolorblind |
not needed |
|
libcroco |
not needed |
|
libgda |
to do |
|
libggz, ggz-client-libs |
not needed |
|
libgpg-error |
not needed |
|
libgcrypt |
not needed |
|
libgsf |
not needed |
|
libical |
not needed |
|
libmapi |
to do |
|
libmusicbrainz |
not needed |
|
libnotify |
||
liboil |
not needed |
|
libproxy |
not needed |
|
libtasn1 |
not needed |
|
libtelepathy |
to do |
|
libxklavier |
not needed |
|
libxml2 |
to do |
|
libxslt |
to do |
|
Mono.Addins |
not needed |
|
mozilla (firefox) |
to do |
|
ndesk-dbus |
not needed |
|
ndesk-dbus-glib |
not needed |
|
opal |
not needed |
|
pkg-config |
to do |
|
to do |
||
PolicyKit-gnome |
to do |
|
pulseaudio |
not needed |
|
poppler |
not needed |
|
pycairo |
not needed |
|
ptlib |
not needed |
|
Python |
to do |
|
rarian |
not needed |
|
shared-mime-info |
not needed |
|
sqlite |
not needed |
|
startup-notification |
not needed |
|
swfdec |
to do |
|
system-tools-backends |
not needed |
|
telepathy-glib |
||
telepathy-mission-control |
||
unique |
to do |
|
Other |
||
atomix |
not needed |
|
banshee |
to do |
|
to do |
||
to do |
||
contact-lookup-applet |
to do |
|
eggcups |
to do |
|
f-spot |
not needed |
|
gnome-blog |
to do |
|
not needed |
||
gnome-cups-manager |
to do |
|
gnome-main-menu |
to do |
|
to do |
||
GParted |
to do |
|
GNOME Phone Manager |
to do |
|
to do |
||
to do |
||
gtetrinet |
to do |
|
gthumb |
to do |
|
to do |
||
libbtctl |
to do |
|
libgda |
not needed |
|
libgnomekbd |
to do |
|
libgoffice |
to do |
|
libgsf |
not needed |
|
nautilus-sendto |
||
nautilus-vcs |
to do |
|
nemiver |
not needed |
|
to do |
||
network-manager-applet |
||
to do |
||