Intent to Ship: Remove clamping of setTimeout(..., 0)

653 views
Skip to first unread message

Lin, Wanming

unread,
Jan 26, 2021, 9:02:12 PMJan 26
to blin...@chromium.org, Zheng, Hong, Philip Jägenstedt

Contact emails

wanmi...@intel.com, hong....@intel.com, foo...@chromium.org

 

Spec

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps

 

No TAG review requested as this does not add/alter any API surfaces.

 

Summary

Calls to setTimeout(..., 0) were previously clamped to a 1 ms timeout for historical reason: https://bugs.chromium.org/p/chromium/issues/detail?id=402694, This is very old, http://trac.webkit.org/changeset/17156 appeared to add it (10/20/06).

 

This is actually a bug since there's no 1ms clamp in the spec, and which will cause scheduling error, e.g.

 

setTimeout(()=> console.log('1ms timeout'), 1);

setTimeout(()=> console.log('0ms timeout'), 0);

 

Outputs:

Chrome 87:  1ms timeout, 0ms timeout

 

Moreover, 1ms clamp may bring performance penalty.

 

 

Link to “Intent to Prototype” blink-dev discussion

N/A

 

Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes

 

Risks

Interoperability and Compatibility

Firefox: no 1ms clamp

Safari: 1ms clamp (WebKit's clamp at https://github.com/WebKit/WebKit/blob/main/Source/WebCore/page/DOMTimer.cpp#L384)

 

           Some tests/live web pages that depended on this 1ms clamp may fail/meet issue.

 

Is this feature fully tested by web-platform-tests? Link to test suite results from wpt.fyi.

No, no specific test for setTimeout(…, 0) is actually 0ms timeout, this is actually not necessary.

 

Entry on the feature dashboard

https://www.chromestatus.com/feature/4889002157015040

 

 

 

Thanks,

Wanming

Manuel Rego Casasnovas

unread,
Jan 28, 2021, 7:53:47 AMJan 28
to Lin, Wanming, blin...@chromium.org, Zheng, Hong, Philip Jägenstedt

On 27/01/2021 03:01, Lin, Wanming wrote:
> Safari: 1ms clamp (WebKit's clamp at
> https://github.com/WebKit/WebKit/blob/main/Source/WebCore/page/DOMTimer.cpp#L384
> <https://github.com/WebKit/WebKit/blob/main/Source/WebCore/page/DOMTimer.cpp#L384>)

Have we checked with WebKit if they have any plans to change this or not
at some point? Is there a WebKit bug report or something?
Maybe you can ask for signals in webkit-dev, see
https://bit.ly/blink-signals

Bye,
Rego

Alex Russell

unread,
Jan 28, 2021, 3:28:15 PMJan 28
to blink-dev, Manuel Rego, hong....@intel.com, Philip Jägenstedt, Lin, Wanming, Mike Taylor
+mike taylor who may have insight into the potential compat risks, given the different behavior between Gecko and WebKit/Blink.

Chris Harrelson

unread,
Jan 28, 2021, 3:35:25 PMJan 28
to Alex Russell, blink-dev, Manuel Rego, hong....@intel.com, Philip Jägenstedt, Lin, Wanming, Mike Taylor
Also, could you say more about the motivations for this work? Are developers facing problems from the 1ms clamping?

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/025bd7a7-6be1-4b77-9c3a-32bb6b295812n%40chromium.org.

Mike Taylor

unread,
Jan 28, 2021, 5:14:07 PMJan 28
to blink-dev, Manuel Rego, hong....@intel.com, Philip Jägenstedt, Alex Russell, Lin, Wanming
Howdy,

In general, I think if Firefox has been able to ship this behavior it's
likely web-compatible (modulo different code paths being served behind
UA sniffing).

There have been subtle race-y JS timing bug differences between sites in
Firefox and Chrome that my old team (at Mozilla) looked at, but
unfortunately I don't have any links to back that up. So there is some
risk that sites are (unintentionally) relying on the old behavior.

That said, aligning with Firefox (and the HTML standard) on this seems
good -- more so if WebKit is willing to do so as well.

A few questions:

What about setInterval?

Will setTimeout and setInterval be consistent wrt clamping after this
proposed change? (see also
https://bugzilla.mozilla.org/show_bug.cgi?id=1646799#c0)
> https://bit.ly/blink-signals <https://bit.ly/blink-signals>
>
> Bye,
> Rego
>
> --
> You received this message because you are subscribed to the Google
> Groups "blink-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to blink-dev+...@chromium.org
> <mailto:blink-dev+...@chromium.org>.
> <https://groups.google.com/a/chromium.org/d/msgid/blink-dev/025bd7a7-6be1-4b77-9c3a-32bb6b295812n%40chromium.org?utm_medium=email&utm_source=footer>.

Wanming Lin

unread,
Jan 29, 2021, 3:54:12 AMJan 29
to blink-dev, Mike Taylor, Manuel Rego, Hong Zheng, Philip Jägenstedt, sligh...@chromium.org, Lin, Wanming
Thanks all for your comments! I've created a WebKit issue at: https://bugs.webkit.org/show_bug.cgi?id=221124

The main motivation of this intent-to-ship is to correct the scheduling and reduce potential performance impact. We didn't find impact on live sites with/without 1ms clamp maybe they‘ve already avoided the usage of setTimeout(..., 0) since compatible risk is really existed. 

> What about setInterval?
Since remove 1ms clamp exits risk, we'd like to change setTimeout at first and base on discussion result to see if it's reasonable, if yes, we can apply it at setInterval as next step.

Yoav Weiss

unread,
Jan 29, 2021, 4:01:37 AMJan 29
to Wanming Lin, blink-dev, Mike Taylor, Manuel Rego, Hong Zheng, Philip Jägenstedt, sligh...@chromium.org
On Fri, Jan 29, 2021 at 9:54 AM Wanming Lin <wanmi...@intel.com> wrote:
Thanks all for your comments! I've created a WebKit issue at: https://bugs.webkit.org/show_bug.cgi?id=221124

The main motivation of this intent-to-ship is to correct the scheduling and reduce potential performance impact. We didn't find impact on live sites with/without 1ms clamp maybe they‘ve already avoided the usage of setTimeout(..., 0) since compatible risk is really existed. 

Do we have numbers on how often `setTimout(... ,0)` is used? (use counters, HTTPArchive, cluster telemetry, etc)
 
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/5c1d6691-1ccd-4451-a491-56990ecc695fn%40chromium.org.

Ben Kelly

unread,
Jan 29, 2021, 10:20:44 AMJan 29
to Yoav Weiss, Wanming Lin, blink-dev, Mike Taylor, Manuel Rego, Hong Zheng, Philip Jägenstedt, sligh...@chromium.org
Its possible folks are using setTimeout(.., 0) as a setImmediate() replacement which would result in high numbers.  But that use case would not be adversely impacted by removing this clamping.

Ben Kelly

unread,
Jan 29, 2021, 10:22:28 AMJan 29
to Yoav Weiss, Wanming Lin, blink-dev, Mike Taylor, Manuel Rego, Hong Zheng, Philip Jägenstedt, sligh...@chromium.org
Also note that if you nest setTimeout(..., 0) enough (5 times?) then you start getting 4ms clamping anyway.  So this is really about the first 4 or so setTimeout(..., 0) calls in a chain.  I don't think this intent is removing the 4ms clamping for nested timeouts.

geoffrey garen

unread,
Feb 1, 2021, 3:01:42 PMFeb 1
to blink-dev, wande...@chromium.org, Wanming Lin, blink-dev, Mike Taylor, Manuel Rego, hong....@intel.com, Philip Jägenstedt, sligh...@chromium.org, yo...@yoav.ws
Note: http://trac.webkit.org/changeset/17156/webkit is not the change that added the minimum timeout clamp. r17156 *reduced* a pre-existing 10ms clamp to 1ms. 

Alex Russell

unread,
Feb 4, 2021, 3:15:11 PMFeb 4
to blink-dev, geoffrey garen, Ben Kelly, Wanming Lin, blink-dev, Mike Taylor, Manuel Rego, hong....@intel.com, Philip Jägenstedt, Alex Russell, yo...@yoav.ws
Thanks for the clarification, Geoffery.

Wanming: we discussed this again at today's API OWNERS meeting and, given what Mike and Ben noted here, we'd like to see this bake for a while on Beta to shake out any potential compat issues. You have my LGTM1 to flag this on for Beta for one release, and as we get evidence back from that, we'd ask you to report it here. On the basis of that update, we'll then potentially approve a stable launch. Does that sound good to you?

Also, if you have any more data as to why this change improves things for users and developers, that would also be helpful.

Regards

Chris Harrelson

unread,
Feb 4, 2021, 3:16:37 PMFeb 4
to Alex Russell, blink-dev, geoffrey garen, Ben Kelly, Wanming Lin, Mike Taylor, Manuel Rego, hong....@intel.com, Philip Jägenstedt, yo...@yoav.ws
LGTM2 for testing on beta and coming back to the API owners with the results.

Wanming Lin

unread,
Feb 4, 2021, 9:34:37 PMFeb 4
to blink-dev, Chris Harrelson, blink-dev, geoffrey garen, wande...@chromium.org, Wanming Lin, Mike Taylor, Manuel Rego, Hong Zheng, Philip Jägenstedt, yo...@yoav.ws, sligh...@chromium.org
Thanks Alex, Chris, very glad to see this great progress!

> You have my LGTM1 to flag this on for Beta for one release, and as we get evidence back from that, we'd ask you to report it here. On the basis of that update, we'll then potentially approve a stable launch.

Since I'm new to intent-to-ship process, could you please guide me or provide BKMs on how to flag this on for Beta for one release, and what kinds of testing should be covered? Any chromium program could help test and evaluate the impact?

Besides, I am thinking of leveraging chrome://histograms/ to count the use of setTimeout(..., 0) from some hot websites, then we can do some basic testing to check if there's obvious regression. Does it make sense?

Thanks,
Wanming

Philip Jägenstedt

unread,
Feb 5, 2021, 11:01:24 AMFeb 5
to Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org
Hi Wanming,

The most straightforward way to test this on beta (and canary before that) would be to land the code right after the M90 branch point (Feb 25) and then revert it some time well ahead of the M91 branch point (Apr 8). The beta promotion should be around Mar 11, so you should be able to get at least a few weeks on beta with this method.

However, even if the beta baking does not reveal any issues, breakage due to this can be hard to understand, and could be in code (libraries) that aren't easy to update. It would be prudent to make this a finch-controlled experiment, to avoid a potential urgent revert in a point release.

LGTM3 to trying this on beta with whichever method you prefer at the moment.

Best regards,
Philip

Wanming Lin

unread,
Feb 7, 2021, 9:07:07 PMFeb 7
to blink-dev, Philip Jägenstedt, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org, Wanming Lin
Philip, thanks for your comments! I've submitted the reland CL at https://chromium-review.googlesource.com/c/chromium/src/+/2636507/,  please take a look.

Philip Jägenstedt

unread,
Feb 8, 2021, 4:28:00 AMFeb 8
to Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org
Thanks Wanming, I'll review on the CL.

Can you check back in this thread on the week of March 22, so that there will be enough time to discuss before the branch point?

Ian Kilpatrick

unread,
Feb 8, 2021, 11:48:28 AMFeb 8
to Philip Jägenstedt, Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org
Philip - if you could also email the release engineers directly about this change - that likely would be pertinent (just so this is on their radar in case things go wrong, and if a revert in Beta is needed).

Ian 

Wanming Lin

unread,
Feb 8, 2021, 8:09:13 PMFeb 8
to blink-dev, ikilp...@chromium.org, Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org, Philip Jägenstedt
> Can you check back in this thread on the week of March 22, so that there will be enough time to discuss before the branch point?

Sure. :)

Philip Jägenstedt

unread,
Feb 9, 2021, 5:14:15 PMFeb 9
to Ian Kilpatrick, Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org
Good idea, Ian, I'll go ahead and do that.

Wanming Lin

unread,
Mar 28, 2021, 10:27:34 PM (13 days ago) Mar 28
to blink-dev, Philip Jägenstedt, Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org, ikilp...@chromium.org
All, the CL has been landed at https://chromium-review.googlesource.com/c/chromium/src/+/2730350, sorry for a bit delay due to another reverting during the period.

Philip, could you help to  email the release engineers about this change?

Philip Jägenstedt

unread,
Mar 29, 2021, 6:03:04 AM (13 days ago) Mar 29
to Wanming Lin, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org, ikilp...@chromium.org
Hi Wanming,

I think the original timeline here won't work since your CL was reverted and relanded so many times, and I think I also made a mistake with the branching, since a change landed after the M90 branch point would never be in the M90 beta...

To bake in the the M91 beta, what we need to do is:
  • Land the change soon before the M91 branch point, which the latest reland did
  • Allow the change to reach M91 beta (promoted Apr 22)
  • Revert it on the M91 branch well before the stable cut/release, let's say May 4 at the latest
Exactly how much exposure on the beta channel that will give depends on beta release dates, but it ought to be at least a week. 

Does that sound right to you? If so I can ask the release managers about this plan.

Best regards,
Philip

Wanming Lin

unread,
Mar 29, 2021, 11:00:44 PM (12 days ago) Mar 29
to blink-dev, Philip Jägenstedt, blink-dev, Chris Harrelson, geoffrey garen, wande...@chromium.org, Mike Taylor, Manuel Rego, Hong Zheng, yo...@yoav.ws, sligh...@chromium.org, ikilp...@chromium.org, Wanming Lin
> Does that sound right to you? If so I can ask the release managers about this plan.

Yeah, that sounds good! Thank you for your support!

Reply all
Reply to author
Forward
0 new messages