Re: [Web-Facing Change PSA] Remove clamping of setTimeout(..., 0)

121 views
Skip to first unread message

Philip Jägenstedt

unread,
Jan 19, 2021, 4:18:50 AM1/19/21
to Lin, Wanming, blin...@chromium.org, Zheng, Hong
Hi everyone,

I created a chromestatus.com entry for this while reviewing the CL and suggesting this PSA.

Landing the change required updating a lot of tests that began failing, and after landing the CL was found to have caused flakiness and reverted. That can all be dealt with, but some breakage similar to this affecting web developers seems likely, whether affecting live sites or their testing setup.

Unfortunately it doesn't seem like a good idea to log a console message for every use of setTimeout(..., 0), since the vast majority of them will not be problematic.

This will need to be listed in our release notes, and the chromestatus.com entry should ensure that, but that will not help in most cases when a web developer notices that something has stopped working and starts looking for the cause.

I wonder if we shouldn't make this a finch-controlled rollout? Looking to other API owners for their thoughts...

Best regards,
Philip

On Mon, Jan 18, 2021 at 2:56 PM Lin, Wanming <wanmi...@intel.com> wrote:

Hi Chromium developers,

 

Calls to setTimeout(..., 0) were previously clamped to a 1 ms timeout, instead of resulting in a callback as soon as possible. This clamping is being removed. To get the old behavior, please use setTimeout(..., 1) instead.

 

References

 

Thanks,

Wanming

Chris Harrelson

unread,
Jan 19, 2021, 11:41:30 AM1/19/21
to Philip Jägenstedt, Sami Kyostila, Scott Haseley, Lin, Wanming, blin...@chromium.org, Zheng, Hong
Hi,

This change has been attempted or discussed many times over the years. Have all of the reasons why it was 1ms been resolved?

--
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/CAARdPYcBb6a%2B8Q%3DtAPJLc5qgRp2ixnm-YBwVDpFHeCbzqWf7eQ%40mail.gmail.com.

Ian Kilpatrick

unread,
Jan 19, 2021, 11:43:14 AM1/19/21
to Philip Jägenstedt, Lin, Wanming, blin...@chromium.org, Zheng, Hong
This seems like a pretty high-risk change, and some due diligence will likely be warranted. E.g. will this change task ordering if some code is using setTimeout(0) with a setImmediate polyfill? (using postMessage etc)?

On Tue, Jan 19, 2021 at 1:18 AM Philip Jägenstedt <foo...@chromium.org> wrote:
--

Lin, Wanming

unread,
Jan 19, 2021, 12:46:57 PM1/19/21
to blin...@chromium.org, Philip Jägenstedt, Zheng, Hong

Chris Harrelson

unread,
Jan 19, 2021, 12:49:44 PM1/19/21
to Ian Kilpatrick, Philip Jägenstedt, Lin, Wanming, blin...@chromium.org, Zheng, Hong
I think we need an intent-to-ship for this change that reviews the compat risks as well as implementation status in other browsers.

I see the original CL was reverted for an unrelated reason, please don't reland until we've discussed further on the intent-to-ship.

Thanks,
Chris

Yoav Weiss

unread,
Jan 19, 2021, 1:17:12 PM1/19/21
to Chris Harrelson, Ian Kilpatrick, Philip Jägenstedt, Lin, Wanming, blin...@chromium.org, Zheng, Hong
+1 - this seems like a high risk change, so we need to properly discuss it.

Wanming Lin

unread,
Jan 20, 2021, 9:03:24 PM1/20/21
to blink-dev, yo...@yoav.ws, ikilp...@chromium.org, Philip Jägenstedt, Lin, Wanming, blin...@chromium.org, Hong Zheng, Chris Harrelson
Tried a simple  code snippet below:

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

Outputs:

Chrome 871ms timeout, 0ms timeout
Safari 14.0.1: 1ms timeout, 0ms timeout
FireFox 84.0.2: 0ms timeout, 1ms timeout

So both Chrome and Safari use 1ms clamp, while no clamp on FireFox.

Ian Kilpatrick

unread,
Jan 21, 2021, 2:20:34 PM1/21/21
to Wanming Lin, yo...@yoav.ws, Philip Jägenstedt, blin...@chromium.org, Hong Zheng, Chris Harrelson
There is a little additional complexity here when it comes to other task sources used for scheduling. E.g.

I tried above with the patch, and we have the following:
FF: postmessage, 0ms, 1ms
WithPatch: 0ms, postmessage, 1ms
WithoutPatch, postmessage, 1ms, 0ms

This could be fine! But we should likely be careful.
Ian

Wanming Lin

unread,
Jan 26, 2021, 10:50:19 PM1/26/21
to blink-dev, ikilp...@chromium.org, yo...@yoav.ws, Philip Jägenstedt, blin...@chromium.org, Hong Zheng, Chris Harrelson, Wanming Lin
Reply all
Reply to author
Forward
0 new messages