Repository navigation
fix(dispatching): Let Low/Idle work run while every frame is busy - #25858
MartinZikmund merged 2 commits into
Conversation
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 242602 found UI Test snapshots differences: Details
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 242855 found UI Test snapshots differences: Details
|
|
|
f404f08 to
7f23d35
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243342 found UI Test snapshots differences: Details
|
7f23d35 to
6e21764
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Xiaoy312
left a comment
There was a problem hiding this comment.
Approving: the starvation is real and the bound is a good fix. A few suggestions inline, the first one being the only one I'd really like addressed (here or as a follow-up):
- Gate the starved item behind Normal too, not only High (inline on
TryDequeueStarvedLowPriorityItem). - #24040 touches the same render-budget logic; is it going to be closed, or how do the two combine if both land?
- Nits: the second commit (
[UITestClass]) fixes the test file from the first one, worth folding in since we merge with merge commits; thearea/automationlabel looks off for a dispatcher change.
CI note: the failures so far are pre-existing (Android TextBox/ScrollViewer shards 0/4, Given_InputPane.When_OccludedRect_Cleared_Then_Content_Restored and Given_Image_Release.When_Stream_Load_Superseded_After_Decode_Then_Abandoned_Surface_Released both fail on master too, NativeAOT NU1903 is on master as well). Unit Tests Run, macOS and iOS were still pending when I looked.
6e21764 to
cbb63e4
Compare
|
Thanks @Xiaoy312. On the other points:
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243769 found UI Test snapshots differences: Details
|
cbb63e4 to
f41c1cb
Compare
A render action outranks every queue, and each frame queues its layout and Rendering tick at Normal, so a UI thread that is busy on every frame never reached the Low and Idle queues: RunIdleAsync and Low DispatcherQueue work never ran while rendering was saturated. After three renders with Low/Idle work waiting, the dispatcher now runs one such item ahead of the render action and Normal work (never ahead of High), bounding both sides (fixes unoplatform#24032). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A starved Low/Idle item now only runs ahead of the next render, never ahead of queued High or Normal work (await continuations post at Normal), so RunIdleAsync still means nothing else is pending. In a saturated loop the frame's Normal tick has already run when the next render is due, so the starvation bound still applies. Also traces the starved dispatch, notes that the bound counts per composition target, and stops the test pump from posting extra turns behind a pending dispatch. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 244091 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
GitHub Issue: closes #24032
PR Type:
🐞 Bugfix
What changed? 🚀
While the UI thread is busy on every frame, Low and Idle dispatcher work never runs:
CoreDispatcher.RunIdleAsyncandDispatcherQueue.TryEnqueue(Low, …)callbacks wait indefinitely.Cause.
NativeDispatcher.DispatchItemshands out a pending render action before scanning the queues, and each rendered frame queues its layout/Renderingtick at Normal (CoreServices.RequestAdditionalFrame). When a frame's work exceeds the frame interval, the next render action is already pending every time the dispatcher picks, so it alternates render action → Normal tick → render action, and the Low/Idle queues are never reached.The macOS CI hangs this issue was filed for stopped when macOS moved to a paced render thread (#23594, merged with
feature/breakingchangeson 2026-09-02): no stall over 120 s in the macOS runtime-test logs of any sampled master build since. The starvation itself remains on every host once frames are saturated.Fix. The dispatcher counts render actions handed out while Low/Idle work is waiting. After 3, the next turn runs one Low/Idle item ahead of the render action and Normal work (never ahead of pending High work). Idle work then waits a bounded few frames, and rendering yields at most one item every 3 frames.
#24040 seeds the render budget from the Low/Idle counts as well, but that slot is consumed by the per-frame Normal tick (the queues are always picked in priority order), so it doesn't change the measurements below. The unit tests here reuse its deterministic dispatcher harness.
How WinUI behaves. WinUI runs a whole frame as one tick delivered through a
DispatcherQueueTimerat input priority, treats frame requests made inside a tick (Rendering, animations) as low priority, and only queues the next tick from the compositor thread after the previous one ends (UIThreadScheduler.cpp,xcpwindow.cpp). It interleaves rather than guarantees, so saturated frames delay Low work by about 1–3 s there. This fix bounds it tighter than WinUI; matching WinUI's frame scheduling (one tick per frame, queued by the render thread) would be a largerCompositionTargetchange.Measurements (Skia Win32, fixed 60 fps pacing, a
CompositionTarget.Renderinghandler doing fixed work per frame, thenDispatcherQueue.TryEnqueue(Low, …)):Validation
Given_NativeDispatcher): Low and Idle work runs within a few frames of a saturated render loop, a 50-item idle backlog doesn't hold rendering back, and priority order is unchanged when not rendering. On master, Low/Idle work never runs over 67 frames and the backlog test gets 0 items through; with this PR all 4 pass.Uno.UI.UnitTestsoverall: 4439 pass; the 14 failures are calendar/timezone tests that fail on the local machine's timezone regardless.Given_DispatcherQueue,Given_DispatcherQueueTimer,Given_DispatcherTimer,Given_DispatcherHelper: 18/18. A full-suite A/B against master stopped at a 90 min cap (the local session was disconnected, which throttles Win32 presentation); over the 4,980 tests both runs reached, the final failures match, apart fromWhen_Foreground_Changed_With_ShowAsMonochrome_True, which passes 3/3 in isolation.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code