Re: CPU consumption with GtkThread

Maxence Guesdon <[email protected]> Wed, 15 Dec 2010 08:53:26 +0100
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Organization INRIA
Message-ID <20101215085326.53108569@alcazar>
On Wed, 15 Dec 2010 16:24:17 +0900
Jacques Garrigue <[email protected]> wrote:

> On Wed, Dec 15, 2010 at 3:43 PM, Maxence Guesdon
> <[email protected]> wrote:
> > On Tue, 14 Dec 2010 12:18:00 +0100
> > Adrien <[email protected]> wrote:
> >
> >> Hi,
> >>
> >> I actually made it adaptive later on[1]. The drawback was that
> >> animations could take more time to update. The adaptative version
> >> worked quite well but reducing the delay wasn't instantaneous. It was
> >> pretty dumb and experimental, I could probably put more thought in it
> >> if needed.
> >> One of my test was using the acid3 test[2]. Basically, each step of
> >> the animation required one iteration of the loop. So depending on your
> >> uses it might or might not be a good idea.
> >
> > Maybe the GtkThread module could allow setting some kind of callback so
> > that the application could change this delay when needed ?
> 
> I was not aware of this GtkThread problem, but I'm certainly not opposed to
> making the delay tweakable by the application. One difficulty is that I suppose
> this depends quite a lot on the OS scheduler, and in particular on its
> granularity,
> so that the application may not know enough to set this value properly, but at
> least it is better than nothing.

I just commited a proposition. 

This allows setting directly the delay with 
  GtkThread.set_do_jobs_delay

The default delay is not 0.013 instead of 0.0001.

There is also a callback which can be passed to GtkThread.main and
GtkThread.thread_main, which is then passed to GtkThread.thread_main_real.

This callback is called at the end of the external loop in
thread_main_real, so that the application can use this callback to set an
adaptative delay policy, as Adrien does in [1].

This callback is not passed to the thread_main function registered in
GMain.main, I don't know if it would be wishable.

I tested the set_do_jobs_delay, not the callback. And my application does
not use threads extensively.


Regards,

Maxence

[1] http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=caravel/caravel.git;a=blob_plain;f=gtk_thread_bis/gtkThreadBis.ml;hb=67e29bc6550603fa42857569eb6f878f180949f2