This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 15379 - Hi, i was wondering why there is explicit hard limit of how setTimeout works. In spec it says: 6.3 Timers ... "4. If the currently running task is a task that was created by the setTimeout() method, and timeout is less than 4, then increase timeout to 4."
Summary: Hi, i was wondering why there is explicit hard limit of how setTimeout works....
Status: RESOLVED WONTFIX
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-02 03:44 UTC by contributor
Modified: 2012-02-02 01:20 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2012-01-02 03:44:42 UTC
Specification: http://dev.w3.org/html5/spec/Overview.html
Multipage: http://www.whatwg.org/C#top
Complete: http://www.whatwg.org/c#top

Comment:
Hi, i was wondering why there is explicit hard limit of how setTimeout works.
In spec it says:

6.3 Timers
...

"4. If the currently running task is a task that was created by the
setTimeout() method, and timeout is less than 4, then increase timeout to 4."

I think if browser implementors want, they should be allowed to allow smaller
(or even fractional) timeouts! I work on real-time JS and this is really
important to me. If anything, spec should say that timeouts less than 4 ms are
not guaranteed to happen in declared time. Spec should also say, what to do
when timeout <= 0, but should not force implementors to make their
implementations limited.

For example ua should be able to determine on its own if it will allow small
delays or not (based on system/cpu load, context switching, reflow/redisplay
frequency, how much such small delays was requested recently, is device a
battery powered, etc.).

For me it is completely artificial limitation in spec. I also find that Opera
for example allow me specific 1ms or 0.01ms timeout, and it works well
(allowing about 15000 context switches per second on my machine, instead of
just about 240 in Firefox or Chrome). It make many tasks much more responsive!



Witold Baryluk


Posted from: 91.213.255.7
User agent: Opera/9.80 (X11; Linux i686; U; pl) Presto/2.10.229 Version/11.61
Comment 1 Boris Zbarsky 2012-01-02 05:26:00 UTC
Chrome actually tried to put the timeout clamp at 1ms initially.  They discovered that this was not web-compatible and broke sites, which is why they raised it to 10.

I can confirm that Opera's clamp seems to be lower, though.  On this testcase:

  var t = 0;
  var start = new Date;
  function f() {
    if (++t == 1000) {
      alert(new Date - start);
    } else {
      setTimeout(f, 1);
    }
  }
  setTimeout(f, 1);

I get numbers on the order of 1300 alerted in Opera (and same thing with smaller timeout values)...

On the other hand, if I pass 0 for the timeout, Opera clamps it to 4ms, so it has a weird discontinuous behavior subject to floating-point rounding errors which may not be all that desirable either.
Comment 2 Boris Zbarsky 2012-01-02 05:26:52 UTC
Oh, and the point is that it's _possible_ that web compat only requires that 0 be clamped to 4ms, not that other small values be so clamped.  I sort of doubt that given the number of sites I've seen pass "1" in there when they really don't mean it, but it's possible.
Comment 3 Ian 'Hixie' Hickson 2012-02-02 01:20:06 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Rejected
Change Description: no spec change
Rationale: 4ms gives you 250Hz frequency, which is quite adequate enough for pretty much any valid purposes.