The purpose of this work is to allow timers to fire slightly ahead of their scheduled time. This addresses the frequent problem that I have observed that TimerThread gets woken up before it is supposed to (by an average of ~0.4ms on Windows). Without early firing, most of these early wake-ups is a wasted wake-up as we frequently go back to sleep just to wake up again shortly thereafter to actually fire the timers that we had intended to. There is already functionality in place (in TimerThread) to allow early firing but: 1) it only applies to timers _after_ the first timer in a wake-up 2) the tolerance is calculated at run-time based on half of the minimum resolution of PRIntervalTime. This made sense at one point long ago when we used PRIntervals for sleeping but this is no longer the case. This method of determining the early firing tolerance also means that we could have different tolerances on different platforms. This change needs to precede https://bugzilla.mozilla.org/show_bug.cgi?id=1826224. If we increase the timer resolution, which potentially increases the frequency at which we wake up, we end up with an avalanche of wasted wake-ups so we need to make sure that this problem is addressed first.
Bug 1831014 Comment 0 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
The purpose of this work is to allow timers to fire slightly ahead of their scheduled time. This addresses the frequent problem that I have observed that TimerThread gets woken up before it is supposed to (by an average of ~0.4ms on Windows). Without early firing, most of these early wake-ups is a wasted wake-up as we frequently go back to sleep just to wake up again shortly thereafter to actually fire the timers that we had intended to. There is already functionality in place (in TimerThread) to allow early firing but: 1) it only applies to timers _after_ the first timer in a wake-up 2) the tolerance is calculated at run-time based on half of the minimum resolution of PRIntervalTime. This made sense at one point long ago when we used PRIntervals for sleeping but this is no longer the case. This method of determining the early firing tolerance also means that we could have different tolerances on different platforms. This change needs to precede https://bugzilla.mozilla.org/show_bug.cgi?id=1826224. If we increase the timer resolution, which potentially increases the frequency at which we wake up, without first addressing this problem we will end up with an avalanche of wasted wake-ups.