microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.93k stars 29.52k forks source link

Webview: throttling of `setTimeout` and `setInterval` #232788

Open smcenlly opened 1 month ago

smcenlly commented 1 month ago

Does this issue occur when all extensions are disabled?: Yes

We make heavy use of Webviews via the VS Code API. We have observed that setTimeout and setInterval calls are throttled. When the time is less than 1000ms, the time will be overridden to 1000ms as a minimum.

We can reproduce the problem on both MacOS and Windows.

We found that the problem is much harder (and sometimes impossible) to reproduce when display refresh rate is higher. With a refresh rate of 60hz, the problem is fairly easy to reproduce.

We have created a sample repo that shows the problem.

Steps to Reproduce:

  1. Download the sample repo to reproduce from https://github.com/wallabyjs/webview-issue
  2. Open this example in VS Code 1.47+
  3. Run npm install
  4. Run npm run watch or npm run compile
  5. F5 to start debugging
  6. Run the Webview Issue: Reproduce Webview Issue command to create the webview.
  7. Note the time displayed in the webview:
Expected time to update: 500ms
Actual time to update: 500ms

The two times should be similar.

  1. If you do not have the issue, close and re-open the webview multiple times. Eventually, the actual time will update at ~1000ms instead of 500ms.

Note: it can sometimes take a few times before the throttling starts to occur.

smcenlly commented 4 days ago

Any update on this? For interactive web views that implement rich ui features (e.g. with debounce, etc.) this can issue can be quite problematic.