Increase the nesting threshold before which setTimeout(..., <4ms) start being clamped, from 5 to 100. setTimeout(..., 0) is commonly used to break down long Javascript tasks and let other internal tasks run, which prevents the browser from hanging. setTimeouts and setIntervals with an interval < 4ms are not clamped as aggressively as they were before. This improves short horizon performance, but websites abusing the API will still eventually have their set setTimeouts clamped

Motivation

From https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html "If nesting level is greater than 5, and timeout is less than 4, then set timeout to 4." The intention behind 4ms throttling is to prevent poorly-coded websites from consuming all resources when running in a tight setTimeout(0) loop. A max nesting level of 5 is quite aggressive and we're standing next to a performance cliff. Increasing the max nesting level to 7 improves speedometer 2.0 score by as much as 10% on Macbook Air M1 in Chrome. Removing the throttling logic entirely poses a risk of breaking websites described above. However, having a fixed threshold in the spec is too restrictive, and I suspect that the nesting level threshold can safely be increased by a significant amount since it will quickly be reached by any website abusing setTimeout(0).

Documentation

Specification

Specification link


Unknown standards status - check spec link for status

Status in Chromium

Blink


Origin trial (tracking bug)

Consensus & Standardization

After a feature ships in Chrome, the values listed here are not guaranteed to be up to date.

  • No signal
  • No signal
  • No signals

Owner

Comments

Targeting beta 50% for at least 8 weeks for more chance of teasing out breakage. Will send a follow-up with what we learn prior to experimenting on Stable.

Last updated on 2022-05-14