Opened 13 years ago

Closed 13 years ago

#1585 closed Enhancement (fixed)

Use g_timeout_add_seconds for less wake-ups

Reported by: andrewsomething Owned by: charles
Priority: Low Milestone: 1.41
Component: GTK+ Client Version: 1.40
Severity: Normal Keywords:


Please see for more info

One of the features of GTK+ is that it provides two timeout functions: gtk_timeout_add and gtk_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.

Patch changing instances of g_timeout_add to g_timeout_add_seconds attached.

Hope this is useful....

Attachments (1)

timeout_add_seconds.patch (5.4 KB) - added by andrewsomething 13 years ago.

Download all attachments as: .zip

Change History (7)

Changed 13 years ago by andrewsomething

comment:1 Changed 13 years ago by wereHamster

charles, why is there sometimes 2 seconds, sometimes 1.666 seconds and sometimes 2.5 seconds? Can't that be changed all to 2 seconds?

comment:2 Changed 13 years ago by charles

  • Milestone changed from None Set to 1.50
  • Status changed from new to assigned
  • Type changed from Bug to Enhancement

andrewsomething: the patch is simple & straightforward, and I'm tempted to use it as-is... however that would break Transmission for users who have glib < 2.14.

Would you be interested in revising the patch to add a new function tr_timeout_add_seconds(), which would have an "#if GLIB_CHECK_VERSION(2,14,0)" block to decide whether to use g_timeout_add_seconds() or g_timeout_add()?

Then all the other parts of the patch could invoke that function. That way glib >= 2.14 users would reap the benefits, but users with older machines would still be able to use Transmission.

comment:3 Changed 13 years ago by charles

tr_timeout_add_seconds() should go in gtk/util.[ch]

comment:4 Changed 13 years ago by charles

wereHamster: most of those intervals are arbitrary. I tested out different values and went with what felt right.

comment:5 Changed 13 years ago by andrewsomething

That definitely makes sense if you don't want to bump the glib version, but honestly I'm not all that well versed in C. So by the time I get the formatting right, you could probably do it much quicker. You could do something like this:

#if !GTK_CHECK_VERSION(2,14,0)
#define g_timeout_add_seconds(seconds, callback, user_data) 
g_timeout_add(seconds * 1000, callback, user_data)


comment:6 Changed 13 years ago by charles

  • Milestone changed from 1.50 to 1.41
  • Resolution set to fixed
  • Status changed from assigned to closed

Added to 1.4x branch in r7463.

Added to trunk in r7464.

Note: See TracTickets for help on using tickets.