← Back to release summary

Increased max nesting level for setTimeout(0)

Category
JavaScript
Type
No developer-visible change
Status
No longer pursuing (Chrome No longer pursuing)
Intent stage
Prepare to ship

Summary

Increase the nesting threshold before which setTimeout(..., <4ms) start being clamped, from 5 to 15. 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).

Standards & signals

Ecosystem

Docs: https://docs.google.com/document/d/1boT0k8BQjl7mXXzvI9SdN4XJPSza27vE8T0CNxmMhCI

View on chromestatus.com