<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<div class="moz-cite-prefix">On 2017-04-27 8:49 PM, Ehsan Akhgari
wrote:<br>
</div>
<blockquote
cite="mid:CANTur_7ncGbv+hfuyMRu7hGdRg_14wpNiM4UryjW-qOHVWnwKg@mail.gmail.com"
type="cite">
<div>Timers are terrible for responsiveness and are almost never
what you want. We sometimes use them to lazify some work (do
this part of the initialization in 10 seconds!) or to do some
periodic background task (refresh this cache every second) but
they cause a lot of problems due to the fact that they can
execute at unpredictable times. From the perspective of
improving the responsiveness of Firefox, if your goal is to keep
the main thread as free as possible when the user's input events
are about to be handled, the last thing you want is to start
running one of these timers right before the user clicks or
types or something like that. Gecko now supports the <a
moz-do-not-send="true"
href="https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback">requestIdleCallback
API</a> which allows the caller to request a timer that only
gets dispatched when the application is idle. Where possible,
you should consider re-examining the timers in your areas of the
code and consider using to idle dispatch where appropriate.<br>
</div>
</blockquote>
<br>
Do we have an idle-aware API for scheduling periodic background
tasks that have a *minimum* wait time but don't mind some extra
slack time (i.e. do not refresh the cache more frequently than every
second)? requestIdleCallback() has a timeout option, but it is a
*maximum* wait time. The idle callback could be called almost
immediately, which is not appropriate for periodic background tasks.
Does setTimeout() already consider main thread idleness for long
timeouts like 1 or 10 seconds?<br>
</body>
</html>