[wasm][release/6.0] Reduce number of calls to setTimer #62705
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem description
setTimeoutloop.mono_set_timeout_execin 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
TimerQueuefrom [wasm] Reduce number of calls to setTimer #62433.TimerQueue.Browser.Mono.cssetTimeoutpending for all TimerQueue instances.s_shortestDueTimeMssetTimeoutif current pending is earlier than requested one . Even from different TimerQueue instance.src/mono/wasm/runtime/library_mono.jslastSchedulewhich is the previous registration of pending timer. We callclearTimeouton it, any time new timer is registered.Testing
simple.jsbut not run on CI.globalThis.setTimeoutto be able to observe number of setTimeout calls and number of callback executions.Repro on blazor
Profiling the app for 10 seconds every minute results in the below number of calls to "Install Timer".
00:30:00->00:40:00: 28 calls.
01:30:00->01:40:00: 27 calls.
02:30:00->02:40:00: 32 calls.
03:30:00->03:40:00: 25 calls.
Test with prevent_timer_throttling
Number of scheduled timers is consistent in time (every 1sec).
TODO
Fixes #62227