<div dir="ltr">Andreas (who wasn't previously on this list) has thoughts here so I'm CCing him so he can respond.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 4, 2017 at 3:13 AM, Dão Gottwald <span dir="ltr"><<a href="mailto:dgottwald@mozilla.com" target="_blank">dgottwald@mozilla.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>nsIIdleService and requestIdleCallback use different definitions of idleness, don't they? It was my understanding that nsIIdleService is about user input and requestIdleCallback is roughly about CPU idleness.</div><div><br></div><div></div><div>Looking at what <a href="http://w3.org" target="_blank">w3.org</a> says about requestIdleCallback, I may be partly wrong: "This document defines an API that web page authors can use to
cooperatively schedule background tasks such that they do not introduce
delays to other high priority tasks that share the same event loop, such
as input processing, animations and frame compositing. The user agent
is in a better position to determine when background tasks can be run
without introducing user-perceptible delays or jank in animations and
input response, based on its knowledge of currently scheduled tasks,
vsync deadlines, user-interaction and so on. Using this API should
therefore result in more appropriate scheduling of background tasks
during times when the browser would otherwise be idle."</div><div><a href="https://www.w3.org/TR/requestidlecallback/" target="_blank">https://www.w3.org/TR/<wbr>requestidlecallback/</a></div><div><br></div><div>This seems to be intentionally underspecified, so it's up to Gecko to define idleness. It would be nice if MDN documented this, along with examples where using
requestIdleCallback actually makes sense and others where it may be useless / harmful (e.g. considering battery life).</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">2017-05-04 0:18 GMT+02:00 Ehsan Akhgari <span dir="ltr"><<a href="mailto:ehsan.akhgari@gmail.com" target="_blank">ehsan.akhgari@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Wed, May 3, 2017 at 3:33 PM, Chris Peterson <span dir="ltr"><<a href="mailto:cpeterson@mozilla.com" target="_blank">cpeterson@mozilla.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF"><span class="m_-6923802544103112950m_-7762840324681052273gmail-">
<br>
<br>
<div class="m_-6923802544103112950m_-7762840324681052273gmail-m_-6068862779398075595moz-cite-prefix">On 2017-04-27 8:49 PM, Ehsan Akhgari
wrote:<br>
</div>
</span><span class="m_-6923802544103112950m_-7762840324681052273gmail-"><blockquote 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 href="https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback" target="_blank">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></span>
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.</div></blockquote><div><br></div></span><div>Does nsIIdleService::AddIdleObserve<wbr>r() <<a href="https://searchfox.org/mozilla-central/rev/b0e1da2a90ada7e00f265838a3fafd00af33e547/widget/nsIIdleService.idl#55" target="_blank">https://searchfox.org/mozilla<wbr>-central/rev/b0e1da2a90ada7e00<wbr>f265838a3fafd00af33e547/<wbr>widget/nsIIdleService.idl#55</a>> fit this use case?</div><div><br></div><div>(We also have the idle-daily notification BTW that fires at most once a day when the user is idle which is typically used for background maintenance work.)<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF">Does setTimeout() already consider main thread idleness for long
timeouts like 1 or 10 seconds?<br>
</div></blockquote></span></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">No, it doesn't take the main thread idleness into account for anything at all.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Cheers,<span class="m_-6923802544103112950HOEnZb"><font color="#888888"><br></font></span></div><span class="m_-6923802544103112950HOEnZb"><font color="#888888"><div class="gmail_extra">-- <br><div class="m_-6923802544103112950m_-7762840324681052273gmail_signature"><div dir="ltr">Ehsan<br></div></div>
</div></font></span></div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
firefox-dev mailing list<br>
<a href="mailto:firefox-dev@mozilla.org" target="_blank">firefox-dev@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/firefox-dev" rel="noreferrer" target="_blank">https://mail.mozilla.org/listi<wbr>nfo/firefox-dev</a><br>
<br></span></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
firefox-dev mailing list<br>
<a href="mailto:firefox-dev@mozilla.org">firefox-dev@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/firefox-dev" rel="noreferrer" target="_blank">https://mail.mozilla.org/<wbr>listinfo/firefox-dev</a><br>
<br></blockquote></div><br></div>