Skip to content

perf(android): Post dispatcher work as async messages - #25487

Merged
ajpinedam merged 2 commits into
masterfrom
dev/mazi/android-async-dispatcher
Oct 27, 2026
Merged

ajpinedam merged 2 commits into
masterfrom
dev/mazi/android-async-dispatcher

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #25486

PR Type:

🐞 Bugfix

What changed? 🚀

NativeDispatcher.Android now posts its work as asynchronous main-looper messages:

  • Handler.CreateAsync on API 28+;
  • Message.Asynchronous = true below that.

Before: the messages were synchronous, so they waited behind the view system's sync barriers.

Why it mattered: until the first Skia frame, the first-frame gate's OnPreDraw returns false. Each false makes ViewRootImpl reschedule its traversal and post a sync barrier every vsync. DispatchItems runs one item per message, so until the first frame the dispatcher ran one item per vsync. Startup awaits a long chain of dispatcher continuations: the font preload's 36 faces, then the page and Loaded. The first frame waited on work that was itself throttled by waiting for the first frame. Choreographer and input already use async messages for the same reason.

Measured on a Pixel Tablet, Release, dev.2275 with this change behind a switch. 6 interleaved cold starts each, ms after process start:

Loaded First frame
Before 2,122 2,652 [2,643..2,677]
After 1,538 2,070 [2,051..2,087]
  • Throughput unchanged: rapid element creation, LOLs and scripted rich-list scrolling are within noise.
  • The gate itself is unchanged: the window still holds its first draw until a frame is presented.

Validation:

  • Runtime: the API 28+ path, on device, measured above.
  • Compile: Uno.UI.Dispatching.netcoremobile (net10.0-android), with analyzers.
  • Not runtime-validated: the pre-API-28 Message fallback.

No automated test: the runtime tests build as generic net10.0 and can't install a native OnPreDrawListener to recreate the sync barrier.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm

@MartinZikmund MartinZikmund added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/performance 📈 Categorizes an issue or PR as relevant to performance labels Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 18s —— View job


Review of #25487

Verdict: ship (with one optional nit).

Issues: 0 high, 0 medium, 1 low (inline).

Cross-cutting notes

  • The change is a root-cause fix. It addresses the sync-barrier throttling directly rather than guarding against its symptoms, and the measured first-frame improvement is credible.
  • It is correctly confined to the .Android.cs partial, with OperatingSystem.IsAndroidVersionAtLeast gating. No platform leakage, and no style or event-rule violations.
  • Async messages bypass sync barriers, so the dispatcher could in principle starve sync-posted work. The PR reports throughput within noise, and Choreographer and input already use async messages, so I don't consider this a blocker.
  • No automated test, which the PR justifies (runtime tests can't install a native OnPreDrawListener). The pre-API-28 fallback is not runtime-validated.
  • Validation in the PR is labelled honestly: Runtime for API 28+ and Compile for net10.0-android. I reviewed by inspection only and did not build.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund MartinZikmund added the 7.0 PRs only. For issues, use the Release field. label Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 11s —— View job


Review of #25487 (re-review after the latest push)

Verdict: ship.

Issues: 0 high, 0 medium, 0 low.

  • The earlier nit is resolved. _hasAsyncHandler is now a static readonly bool with [SupportedOSPlatformGuard("android28.0")], and both Initialize and EnqueueNative use it, so the two checks can't drift.
  • This is a root-cause fix: the dispatcher no longer queues behind the view system's sync barriers. The change stays inside the .Android.cs partial, and the style is consistent (tabs, braces, short why-comment).
  • On API 28+, Handler.CreateAsync makes Handler.Post produce async messages. Below 28, Message.Obtain(_handler, _implementor) with Asynchronous = true and SendMessage is equivalent to Post. I checked this by inspection only.
  • Async messages bypass sync barriers, so the dispatcher could in principle starve sync-posted work. The PR reports throughput within noise, and Choreographer and input already use async messages, so I don't see a blocker.
  • Validation labels in the PR are accurate: Runtime for API 28+, Compile for net10.0-android. The pre-28 fallback is not runtime-validated. A quick check on an API 26/27 emulator before merge would still be worthwhile.
  • I did not build or run anything.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • DisplayInformation.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AppBarButtonTest.png-dark
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png
    • AppWindowClosing.png
    • AppWindowTitleBar Properties.png-dark
    • AppXamlDefinedResources.png
    • Attributed_text_Supserscript.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AutoBorderStretchwithrightmargin.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BackGesture.png-dark
    • BackGesture.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png

@unodevops

Copy link
Copy Markdown
Contributor

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

MartinZikmund and others added 2 commits October 27, 2026 14:22
The first-frame gate's OnPreDraw returns false until a Skia frame is
presented, so the view system posts a sync barrier every vsync. The
dispatcher's synchronous messages waited behind it, running one item
per frame until the first frame: ~0.6 s of cold start (fixes #25486).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm
@ajpinedam
ajpinedam force-pushed the dev/mazi/android-async-dispatcher branch from 1d897b4 to f7d4bde Compare October 27, 2026 18:23
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ajpinedam's task in 12s —— View job


Review of #25487 (re-review after the latest push)

Verdict: ship.

Issues: 0 high, 0 medium, 0 low. I posted no inline comments.

  • _hasAsyncHandler is a single static readonly bool with [SupportedOSPlatformGuard("android28.0")]. Initialize and EnqueueNative both read it, so they can't drift.
  • This is a root-cause fix. Dispatcher messages no longer queue behind the view system's sync barriers. The change stays in NativeDispatcher.Android.cs, with no platform leakage, and follows the style and event rules.
  • Below API 28, Message.Obtain(_handler, _implementor) plus Asynchronous = true and SendMessage should match Handler.Post apart from the async flag. The looper recycles the message, so nothing leaks. I checked this by inspection only.
  • Async messages can in principle starve sync-posted work, but the PR measured throughput within noise, and Choreographer and input already use async messages.
  • Validation labels in the PR are accurate: Runtime for API 28+, Compile for net10.0-android. The pre-28 fallback is still not runtime-validated, so a quick API 26/27 emulator check before merge is worth doing.
  • The "no automated test" justification is reasonable, since the runtime tests can't install a native OnPreDrawListener.
  • I did not build or run anything. I also didn't look into the failed CI build (239541) or the Skia screenshot differences. Neither seems related to a change confined to the Android-only dispatcher partial.

@ajpinedam
ajpinedam enabled auto-merge October 27, 2026 18:24
@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 241732 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_Enumeration.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
  • skia-windows-screenshots: 2458 changed over 2492

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppBarButtonWithIconTest.png
    • ApplicationViewMode.png-dark
    • ApplicationViewSpanningRectsPage.png
    • AppWindowPositionAndSize.png
    • ArcSegment.png-dark
    • Attributed_text_Simple.png-dark
    • AutoBorderStretchwithbottommargin.png
    • AutoBorderStretchwithrightmargin.png-dark
    • AutomationProperties_Name.png
    • AutomationProperties_Relations.png-dark
    • AutoSizedTopLeft.png-dark
    • AutoSizedTopLeft.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png

@mergify

mergify Bot commented Oct 27, 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.

@ajpinedam
ajpinedam merged commit 716c3c0 into master Oct 27, 2026
51 checks passed
@ajpinedam
ajpinedam deleted the dev/mazi/android-async-dispatcher branch October 27, 2026 20:22
ramezgerges added a commit to ramezgerges/uno that referenced this pull request Oct 29, 2026
The Android adapter records most events from a synchronous main-looper
message, which the view system's sync barriers can hold back. Since
unoplatform#25487 the dispatcher posts asynchronous messages that skip those
barriers, so WaitForIdle can return before the record exists, and these
tests failed intermittently on every Android lane. They now poll for the
expected record, and the background-thread action test waits for its
click.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.0 PRs only. For issues, use the Release field. area/performance 📈 Categorizes an issue or PR as relevant to performance platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Cold start ~0.6 s slower: the first-frame gate throttles the UI dispatcher to one item per vsync

4 participants