Skip to content

fix(dispatching): Let Low/Idle work run while every frame is busy - #25858

Merged
MartinZikmund merged 2 commits into
unoplatform:masterfrom
ramezgerges:dev/rara/dispatcher-idle-starvation
Nov 6, 2026
Merged

MartinZikmund merged 2 commits into
unoplatform:masterfrom
ramezgerges:dev/rara/dispatcher-idle-starvation

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

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.RunIdleAsync and DispatcherQueue.TryEnqueue(Low, …) callbacks wait indefinitely.

Cause. NativeDispatcher.DispatchItems hands out a pending render action before scanning the queues, and each rendered frame queues its layout/Rendering tick 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/breakingchanges on 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 DispatcherQueueTimer at 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 larger CompositionTarget change.

Measurements (Skia Win32, fixed 60 fps pacing, a CompositionTarget.Rendering handler doing fixed work per frame, then DispatcherQueue.TryEnqueue(Low, …)):

Work per frame Native WinUI master this PR
0–12 ms 0 ms 0 ms 0 ms
25 ms (saturated) 0.8–3 s never (5 s cap) 77 ms (3 frames), frame rate unchanged

Validation

  • Unit tests (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.UnitTests overall: 4439 pass; the 14 failures are calendar/timezone tests that fail on the local machine's timezone regardless.
  • Runtime (Skia desktop): 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 from When_Foreground_Changed_With_ShowAsMonochrome_True, which passes 3/3 in isolation.
  • Not run locally: macOS, WebAssembly, mobile (same shared dispatcher).

PR Checklist ✅

🤖 Generated with Claude Code

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Oct 31, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 242602 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • AndroidWindowInsets.png-dark
    • Accessibility_ScreenReader.png
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AppBarButtonTest.png
    • AppBarButtonWithIconTest.png
    • AppBarButtonWithIconTest.png-dark
    • ApplicationViewSizing.png-dark
    • ApplicationViewMode.png
    • ApplicationViewMode.png-dark
    • AppBar_KeyBoard.png-dark
    • AppWindowClosing.png-dark
    • AppWindowFeatures.png-dark
    • Application_DispatcherShutdownMode.png
    • Application_DispatcherShutdownMode.png-dark
    • AppWindowPresenters.png-dark
    • AppWindowTitleBar Properties.png
    • AppXamlDefinedResources.png-dark
    • AppWindowPresenters.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AppBarButtonTest.png-dark
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowClosing.png
    • AppWindowPresenters.png-dark
    • ArcSegment.png-dark
    • Attributed_text_Simple.png-dark
    • AutoBorderStretchwithbottommargin.png-dark
    • AutoBorderStretchwithbottommargin.png
    • AutomationProperties_AutomationId.png
    • AutomationProperties_Landmark.png-dark
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • BasicAutoSuggestBox.png-dark
    • BasicAutoSuggestBox.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 242855 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedIconPage.png
    • AppBarButtonWithIconTest.png-dark
    • AppBarToggleButtonTest.png-dark
    • AppBar_KeyBoard.png
    • ApplicationViewSizing.png-dark
    • Application_DispatcherShutdownMode.png-dark
    • AppWindowClosing.png
    • AppWindowPresenters.png-dark
    • AppWindowTitleBar Properties.png
    • Attributed_text_FontSize_Changing.png
    • Attributed_text_FontSize_Changing.png-dark
    • AutoBorderStretchwithleftmargin.png-dark
    • AuthenticationBroker_Cancel.png
    • AutomationPropertiesExtensions_Role.png
    • AutomationPropertiesExtensions_Role.png-dark
    • AutoSuggestBox_Description.png-dark
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBox_Description.png
    • AutoSuggestBoxChosenSuggestion.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • ApplicationViewMode.png
    • AppWindowClosing.png-dark
    • AppWindowPresenters.png-dark
    • ArcSegment.png
    • Attributed_text_Supserscript.png-dark
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithrightmargin.png-dark
    • AutoBorderStretchwithtopmargin.png-dark
    • AutoBorderStretchwithtopmargin.png
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSizedTopLeft.png-dark
    • AutoSizedTopLeft.png
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • AutoSuggestBox_SoftKeboard.png-dark
    • AutoSuggestBox_SoftKeboard.png
    • BasicEnability.png-dark
    • BasicEnability.png

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 242855 has failed on Uno.UI - CI.

@ramezgerges
ramezgerges force-pushed the dev/rara/dispatcher-idle-starvation branch from f404f08 to 7f23d35 Compare November 3, 2026 16:55
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243342 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AppBarButtonWithIconTest.png
    • AppBar_KeyBoard.png
    • ApplicationViewSpanningRectsPage.png
    • AppWindowPositionAndSize.png-dark
    • ArcSegment.png-dark
    • Attributed_text_Simple.png
    • AuthenticationBroker_Demo.png
    • AutomationPropertiesExtensions_Role.png
    • AutomationProperties_AutomationId.png-dark
    • AutoSizedTopLeft.png-dark
    • AutoSizedTopLeft.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowFeatures.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_FontSize_Changing.png
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithtopmargin.png-dark
    • AutomationProperties_Name.png-dark
    • AutomationProperties_Name.png
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • BackGesture.png-dark
    • BackGesture.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BindableDrawerLayout_ChangePane.png-dark
    • BindableDrawerLayout_ChangePane.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png

@ramezgerges
ramezgerges force-pushed the dev/rara/dispatcher-idle-starvation branch from 7f23d35 to 6e21764 Compare November 4, 2026 18:21
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@Xiaoy312 Xiaoy312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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; the area/automation label 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.

@ramezgerges
ramezgerges force-pushed the dev/rara/dispatcher-idle-starvation branch from 6e21764 to cbb63e4 Compare November 4, 2026 21:49
@ramezgerges ramezgerges removed the area/automation Categorizes an issue or PR as relevant to project automation label Nov 4, 2026
@ramezgerges

Copy link
Copy Markdown
Contributor Author

Thanks @Xiaoy312. On the other points:

@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 243769 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AppBarButtonTest.png-dark
    • AppBarButtonWithIconTest.png-dark
    • AppBarToggleButtonTest.png
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSizing.png-dark
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowFeatures.png-dark
    • AppWindowPositionAndSize.png-dark
    • AppWindowPresenters.png
    • AppXamlDefinedResources.png-dark
    • Arrange_Performance01.png
    • Attributed_text_Simple.png-dark
    • Attributed_text_Supserscript.png
    • AuthenticationBroker_Demo.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutomationProperties_Landmark.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_Landmark.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AppBarButtonWithIconTest.png-dark
    • ApplicationViewMode.png-dark
    • Application_DispatcherShutdownMode.png
    • AppWindowTitleBar Properties.png-dark
    • ArcSegment.png-dark
    • Attributed_text_Simple.png
    • AutoBorderStretchwithbottommargin.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutomationProperties_Relations.png-dark
    • AutomationProperties_Relations.png
    • AutoSuggestBox_Description.png-dark
    • AutoSuggestBox_Description.png
    • AutoSuggestBox_SoftKeboard.png-dark
    • AutoSuggestBox_SoftKeboard.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png

@ramezgerges
ramezgerges force-pushed the dev/rara/dispatcher-idle-starvation branch from cbb63e4 to f41c1cb Compare November 5, 2026 17:54
ramezgerges and others added 2 commits November 5, 2026 12:54
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]>
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 5, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 244091 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AnimatedIconPage.png
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png
    • AppWindowFeatures.png-dark
    • AppWindowPositionAndSize.png
    • ArcSegment.png
    • Attributed_text_Simple.png-dark
    • AuthenticationBroker_Cancel.png
    • AuthenticationBroker_Demo.png-dark
    • AutomationProperties_Name.png-dark
    • AutomationProperties_Name.png
    • AutoSuggestBoxChosenSuggestion.png-dark
    • AutoSuggestBoxChosenSuggestion.png
    • BackGesture.png-dark
    • BackGesture.png
    • Basics.png-dark
    • Basics.png
    • BindableDrawerLayout_ChangePane.png-dark
    • BindableDrawerLayout_ChangePane.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png-dark
    • AnimatedVisualsTestbedPage.png
    • AppBarToggleButtonTest.png
    • ApplicationViewSizing.png
    • AppWindowFeatures.png
    • ArcSegment.png-dark
    • AuthenticationBroker_Cancel.png
    • AutoBorderStretchwithtopmargin.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • BasicAutoSuggestBox.png-dark
    • BasicAutoSuggestBox.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png

@mergify

mergify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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.

@MartinZikmund
MartinZikmund merged commit f20ace9 into unoplatform:master Nov 6, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skia: rendering starves Idle/Low dispatcher work, hanging RunIdleAsync (macOS runtime tests time out)

6 participants