From: Chris M. <ch...@al...> - 2011-02-24 01:40:11
|
On 2/23/2011 3:06 PM, Jason Wilkins wrote: > Re: Timers > > I do think that timer events should be allowed to come in between > other input events. Right now they are processed in between input and > redisplay. The argument is that if I have 10 events and they each > take 10 milliseconds to process then a timer that comes up during the > first input event will have to wait 90ms before it is processed > instead of 10ms. Those are some *awfully* expensive callbacks. On my not-too-fast 2+ GHz PC that amounts to 20 million instructions (cycles). If you need real-time-ish performance (hard to do if you don't have a real time operating system or if you have a "far from real time" operating system), an effective strategy is to make the callbacks very short, just long enough to trigger an asynchronous operation in another thread to do the work (Even assuming a 100x cycle/instruction ratio between a scripted language and the underlying processor, that amounts to 200,000 instructions per callback. Setting a state variable and returning would be order a few instructions so maybe like 0.05msec total. 10 such events would only take 0.5msec. > Another argument is that if freeglut used the > WM_TIMER windows event then it would naturally be processed this way, > but freeglut uses the high performance timer (i assume) so it doesn't > literally consider timers to be events. There is no reason not to > check in between events so that they logically behave like the other > events. For each instance justifying one event being more or less "special" than another, I can see a different application needing the opposite. Good news, if you keep the event handlers lightweight, as long as the event handling is fair and balanced then your application should run ok. For real modifications to the event loop structure, I recommend actual timings and benchmarks to determine where the time is spent and whether a different allocation of resources could improve things. It is probably easier to use the callbacks efficiently than to try to evaluate the cross-platform, multiple application performance matrix required for a real decision with analysis. Cheers, Chris |