Allow (fix) early firing of timers in TimerThread
Categories
(Core :: XPCOM, enhancement)
Tracking
()
Tracking | Status | |
---|---|---|
firefox118 | --- | fixed |
People
(Reporter: jlink, Assigned: jlink)
References
(Blocks 1 open bug)
Details
(Whiteboard: [sp3])
Attachments
(1 file)
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:
- it only applies to timers after the first timer in a wake-up
- 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.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 1•2 years ago
|
||
Need to be careful with early firing. The spec lets UA to fire setTimeout timers late, but not early, if interpreted strictly.
Assignee | ||
Comment 2•2 years ago
|
||
We should definitely be on the watch for any problematic changes in behavior with this change. The catch though is that we are already willing to fire timers early so I'm not really expecting that to happen. (Or, if there were going to be any problems, this would probably just be making them more consistent and reproducible.)
In the future if we decide that we do need to be more strict with JS timeouts then we could add the option for individual timers to not fire early but that would be a much bigger change to the behavior.
Assignee | ||
Comment 3•2 years ago
|
||
- Prior to this change, we allowed any timer except the first to fire early. Being woken up
slightly before our first timer is due was resulting in a lot of "wasted" wake-ups (where we wake
up and do nothing other than go back to sleep). - This change results in waking up TimerThread 10% less frequently in my test case of watching a
YouTube video. - Made the allowed early firing tolerance be a constant value rather than calculated at run-time.
- Also cleaned up some includes.
Comment 5•2 years ago
|
||
Backed out for causing build bustages in TimerThread.h
- Backout link
- Push with failures
- Failure Log
- Failure line: /builds/worker/checkouts/gecko/xpcom/threads/TimerThread.h:26:34: error: base class has incomplete type
Comment 7•2 years ago
|
||
bugherder |
Assignee | ||
Updated•2 years ago
|
Description
•