-
Notifications
You must be signed in to change notification settings - Fork 5k
[wasm] Reduce number of calls to setTimer #62433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
89c2894
to
dc877ce
Compare
...ime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TimerTests.cs
Outdated
Show resolved
Hide resolved
src/mono/System.Private.CoreLib/src/System/Threading/TimerQueue.Browser.Mono.cs
Outdated
Show resolved
Hide resolved
4883d89
to
6ce3dbe
Compare
/azp run runtime-manual |
Azure Pipelines successfully started running 1 pipeline(s). |
6ce3dbe
to
20b4d87
Compare
...eropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/Simple/TimerTests.cs
Outdated
Show resolved
Hide resolved
This is test with the repro sample, when running this PR (net 7.0) It shows that
Current code on Net6.0 has hundred calls to mono_wasm_set_timeout_exec each tick. When the page is out of focus and the browser applies timer throttling
|
cc @m-chandler |
...eropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/Simple/TimerTests.cs
Outdated
Show resolved
Hide resolved
/azp run runtime-manual |
Azure Pipelines successfully started running 1 pipeline(s). |
54719e4
to
ee274a0
Compare
Co-authored-by: Marek Fišera <[email protected]>
ee274a0
to
b71b244
Compare
/azp run runtime-manual |
Azure Pipelines successfully started running 1 pipeline(s). |
...ime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TimerTests.cs
Outdated
Show resolved
Hide resolved
...ime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TimerTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks right to me.
Test is only manual. Xharness version on this branch triggers timer queue in a way that makes the test useless. Co-authored-by: Pavel Savara <[email protected]>
* Port changes to the TimerQueue from #62433. Test is only manual. Xharness version on this branch triggers timer queue in a way that makes the test useless. Co-authored-by: Pavel Savara <[email protected]> * Replace main method with plain static method for running timer tests. * Rename index.html to simple.html to avoid collision with generated index.html for unit tests. Co-authored-by: Pavel Savara <[email protected]>
Problem description
setTimeout
loop.mono_set_timeout_exec
in Net6.0 to prevent timer throttling. That made the underlying problem worse and that's how it was detected.‡ TimerQueue is group of timers, so only shorter than current in the same TimerQueue does that.
Fix
TimerQueue.Browser.Mono.cs
setTimeout
pending for all TimerQueue instances.s_shortestDueTimeMs
setTimeout
if current pending is earlier than requested one . Even from different TimerQueue instance.scheduling.ts
prevent_timer_throttling
, only introduced in Net7.0setTimeout
for better code readability. Removedtimeout_queue
.lastSchedule
which is the previous registration of pending timer. We callclearTimeout
on it, any time new timer is registered.Testing
setTimeout
ignoresdelay
and behaves as it was always 0. V8 could not be used to test timers.globalThis.setTimeout
to be able to observe number of setTimeout calls and number of callback executions.Fix for #62227
TODO