Evaluate aggregating timers to reduce the number of times we wake up the CPU for serving them
Categories
(Core :: DOM: Core & HTML, defect, P5)
Tracking
()
Performance Impact | medium |
People
(Reporter: gsvelto, Unassigned)
References
Details
(Keywords: perf:resource-use)
It might be worth checking if there would be any value in aggregating timers with identical (or close enough) intervals to reduce power consumption. The rationale behind this is that on modern devices (and especially phones) taking the CPU out of standby and into an high-power state has fixed power costs. So, for example if we have two timers with the same interval, making them trigger back-to-back would allow us to save some power compared to having them trigger at separate times. This could also have performance benefits in terms of already warmed up caches. One thing worth analyzing is if how much aggregation could be done without impacting the user experience. While JS timers are not guaranteed to trigger at the exact requested time, merging two 30 minutes timers and having one of the two trigger 15 minutes later than expected might be a little too much. IIRC the Linux kernel should already do something similar in the form of event aggregation (i.e. running interrupt-handlers and such back-to-back when possible instead of waiting for them to trigger) but I'm not sure if this applies to timers as well.
Comment 1•9 years ago
|
||
For avoidance of doubt, are you talking about aggregating JS timers (i.e. setTimeout) or aggregating XPCOM timers (nsITimer)? I'm pretty sure we do the former, though maybe we could be more aggressive in coalescing them...
Reporter | ||
Comment 2•9 years ago
|
||
(In reply to Nathan Froyd [:froydnj] [:nfroyd] from comment #1) > For avoidance of doubt, are you talking about aggregating JS timers (i.e. > setTimeout) or aggregating XPCOM timers (nsITimer)? I'm pretty sure we do > the former, though maybe we could be more aggressive in coalescing them... I was thinking about JS timers. I remember noticing some time ago that the FxOS homescreen was using two setInterval() timers of 1s each and they were firing every 0.5s waking up the phone twice when once would have been enough. I didn't do extensive testing though so I might be wrong. BTW most recent OSes tend to do timer aggregation already but they're not very aggressive; they'll lump two timers together if they're going to tick ms apart from each other but not much more than that.
Comment 3•9 years ago
|
||
We're not very good at aggregating JS timers. There have been pages which make FF slow because of too many nsITimers which are created for JS timers.
Comment 4•3 years ago
|
||
Bulk-downgrade of unassigned, >=5 years untouched DOM/Storage bugs' priority.
If you have reason to believe this is wrong (especially for the severity), please write a comment and ni :jstutte.
Comment 5•3 years ago
|
||
This work is pretty important for mobile, and I would argue is pretty important for being competitive with respect to power consumption in general (laptops etc). I'd like to request that this bug be reconsidered. Thanks!
Comment 6•3 years ago
|
||
We should often be running many setTimeout timers during a single thread level task,
https://searchfox.org/mozilla-central/rev/58e955b8005b4845c42e874a6b9aa5b223ef0d82/dom/base/TimeoutManager.cpp#684 and onward.
This bug was filed way before any of the timeout handling changes landed.
Would be nice to get some data here what to improve.
Comment 7•3 years ago
|
||
(In reply to Aaron Klotz [:aklotz] from comment #5)
This work is pretty important for mobile, and I would argue is pretty important for being competitive with respect to power consumption in general (laptops etc). I'd like to request that this bug be reconsidered. Thanks!
(In reply to Olli Pettay [:smaug] from comment #6)
Would be nice to get some data here what to improve.
Hi Aaron, can you gather such evidence that this is still an issue?
Comment 8•3 years ago
|
||
I'll raise this at my team's weekly meeting tomorrow, though given the timing we might not be able to properly discuss it until the new year.
Adding perf triage tag – seems like a pretty reasonable battery improvement effort for fenix but "collecting a bit of data could help determine if this is high value - Even adding a log that we could read from logcat to see how often this is happening." (quote from acreskey)
Reporter | ||
Comment 10•3 years ago
|
||
The timer implementation has extensive logging built in and it can be turned on dynamically: https://searchfox.org/mozilla-central/rev/dd042f25a8da58d565d199dcfebe4f34db64863c/xpcom/threads/nsTimerImpl.cpp#46
Reporter | ||
Comment 11•3 years ago
|
||
Also switching the platform to All/All because this is most definitely not a B2G-specific thing now though it would help there too :-)
Updated•3 years ago
|
Updated•2 years ago
|
Description
•