Web Worker 是否会限制 setTimeout() / setInterval()?
Does Web Worker throttles setTimeout() / setInteval()?
我在 前景 选项卡上有一个启动(专用)网络工作者的脚本。现在我看到 setTimeout(xxx, 100)
中的网络工作者被限制为每秒被触发的频率不超过一次,而不是根据需要每秒触发 10 次。我已经用谷歌搜索了非活动选项卡的这种限制,但是是否有任何文档对 Web Workers 有同样的说法?我已经在 Chrome 和 Firefox 中检查过了。
虽然 they do allow it:
没有关于这种节流行为的真正规范
- Optionally, wait a further implementation-defined length of time.
This is intended to allow user agents to pad timeouts as needed to optimize the power usage of the device. For example, some processors have a low-power mode where the granularity of timers is reduced; on such platforms, user agents can slow timers down to fit this schedule instead of requiring the processor to use the more accurate mode with its associated higher power usage.
Chrome 从 2017 年开始 this document 他们公开了他们计划如何处理后台标签。
从那里我们可以看到 plan section about Web Workers:
Throttling web workers (~2018)
We are currently instrumenting web workers to better understand their CPU usage and power impact. We consider throttling web workers as well, being thoughtful about minimizing broken content.
原定于 2018 年,here is the issue tracking it's deployment。
还应注意,WICG 目前正在积极讨论实施 Page-Lifecycle API. This API will expose a few events, and a new "frozen" state, which for what we are interested, should also pause Workers' execution。
我在 前景 选项卡上有一个启动(专用)网络工作者的脚本。现在我看到 setTimeout(xxx, 100)
中的网络工作者被限制为每秒被触发的频率不超过一次,而不是根据需要每秒触发 10 次。我已经用谷歌搜索了非活动选项卡的这种限制,但是是否有任何文档对 Web Workers 有同样的说法?我已经在 Chrome 和 Firefox 中检查过了。
虽然 they do allow it:
没有关于这种节流行为的真正规范
- Optionally, wait a further implementation-defined length of time.
This is intended to allow user agents to pad timeouts as needed to optimize the power usage of the device. For example, some processors have a low-power mode where the granularity of timers is reduced; on such platforms, user agents can slow timers down to fit this schedule instead of requiring the processor to use the more accurate mode with its associated higher power usage.
Chrome 从 2017 年开始 this document 他们公开了他们计划如何处理后台标签。
从那里我们可以看到 plan section about Web Workers:
Throttling web workers (~2018)
We are currently instrumenting web workers to better understand their CPU usage and power impact. We consider throttling web workers as well, being thoughtful about minimizing broken content.
原定于 2018 年,here is the issue tracking it's deployment。
还应注意,WICG 目前正在积极讨论实施 Page-Lifecycle API. This API will expose a few events, and a new "frozen" state, which for what we are interested, should also pause Workers' execution。