[dev-platform] Intent to prototype and ship: TimerThread efficiency improvements

57 views
Skip to first unread message

Justin Link

unread,
May 5, 2023, 2:29:14 PM5/5/23
to dev-pl...@mozilla.org

Summary: Changes are planned to the way that timers fire in order to improve efficiency and performance and reduce power consumption.

 


Phase 1:

What: "Bundle" timers together that are firing at similar times and fire them all in a single wake-up. (Bug 1783405) Waking up multiple times to fire timers that are all supposed to fire around the same time is wasteful. This functionality gives TimerThread the option to wake up less frequently and fire more timers each time.

 

Impact:

  • Improved efficiency/reduced power consumption from fewer-wake-ups.
  • Increased timer "lateness". Some timers may fire later (relative to their requested firing time) than they did before. This will only happen when there are multiple timers firing close together.
  • Reduced power consumption. Waking up a thread consumes power. Doing it less should lower power consumption.
  • Note that the impact of this change is pretty negligible on Windows at the moment because most of the time we are only waking up every 16ms anyway. (This will change in Phase 3.)



Phase 2:

What: Allow timers to fire slightly early. (Bug 1831014) Currently when TimerThread wakes up earlier than intended it can't do anything because it is not yet time for the queued timers to fire. It then just goes back to sleep to wake up late enough to fire those timers.

 

Impact:

  • Improved efficiency. This change greatly reduces a significant source of unnecessary/inefficient wake-ups.
  • Improved performance. Reducing wake-ups means more CPU resources are available to do other work.
  • Reduced power consumption. Waking up a thread consumes power. Doing it less should lower power consumption.
  • Reduced timer lateness. The timers that get fired early are exactly the timers that would have been delayed the most prior to this change.


 

Phase 3:

What: Increase timer resolution on Windows when running on AC power (ie, not running on battery). (Bug 1826224)

 

Impact:

  • More precise firing of timers. RIght now, timers only fire when the timer thread is woken up which is generally only every 16ms.
  • Increased power consumption when on AC power. Note that this impact is mitigated by the changes from Phases 1 and 2.
  • Improved performance for dependent timer chains on Windows. When timers trigger other work (including adding new timers)



Phase 4:

What: Fire zero-delay timers immediately without waking up the timer thread. (Bug 1770658)

 

Impact:

  • Improved efficiency. This eliminates one more source of unnecessary/inefficient wake-ups.
  • Improved performance. Reducing wake-ups means more CPU resources are available to do other work.
  • Reduced power consumption. Waking up a thread consumes power. Doing it less should lower power consumption.


-

Justin Link (he/him)

Staff Engineer, Firefox Performance Team

Reply all
Reply to author
Forward
0 new messages