Skip to content

perf: Reduce #US heap size for not-implemented member stubs - #23270

Merged
MartinZikmund merged 4 commits into
masterfrom
dev/mazi/usheap
May 14, 2026
Merged

MartinZikmund merged 4 commits into
masterfrom
dev/mazi/usheap

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented May 14, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #20968

PR Type:

💬 Other... (Performance / binary-size optimization)

What changed? 🚀

#US (user strings) was reported as over 50% of Uno.dll's size. The dominant contributor was the per-member "The member XXX is not implemented... visit https://aka.platform.uno/notimplemented" string baked into every auto-generated [NotImplemented] API stub. Each literal is unique (full member signature + URL-escaped anchor), so the CLR cannot dedupe them in the #US heap.

This PR stops baking the message and instead emits a call to a shared helper, passing only the minimal unique data:

  • src/Uno.Foundation/Metadata/ApiInformation.cs — BuildNotImplementedMessage(type, memberName) builds the message at runtime; CreateNotImplementedException(type, memberName) is the throwing helper used by forceRaise stubs; TryRaiseNotImplemented reuses the shared builder and keys its log-once set on type + "." + memberName.
  • src/Uno.WinAppSDKSyncGenerator/Generator.cs — generated stubs now emit throw ApiInformation.CreateNotImplementedException("Full.Type.Name", "MemberName(signature)"). The member name is stripped of its containing-type prefix and return type (both redundant — the type is passed as arg 1), which both shortens each string and lets identically-named members across types share a single #US entry.
  • Regenerated Generated/ files — every baked message literal replaced with a helper call; zero visit https://...notimplemented literals remain in generated code.

Example emitted call:
throw global::Windows.Foundation.Metadata.ApiInformation.CreateNotImplementedException("Microsoft.UI.Win32Interop", "GetWindowIdFromWindow(nint hwnd)");

The only observable behavior change: NotImplementedException / log messages now read The member GetWindowIdFromWindow(nint hwnd) is not implemented... with a clean #m=Full.Type.Name.GetWindowIdFromWindow(...) doc anchor.

Size impact

Skia variant, summed across the five assemblies that contain Generated/ folders.

Release:

Assembly Before After Saved
Uno.dll (Uno.UWP) 11,108,352 4,331,008 −6,777,344 (−61.0%)
Uno.UI.dll 12,436,480 11,930,112 −506,368 (−4.1%)
Uno.UI.Composition.dll 543,744 381,440 −162,304 (−29.8%)
Uno.Foundation.dll 211,968 207,872 −4,096 (−1.9%)
Uno.UI.Dispatching.dll 32,768 29,184 −3,584 (−10.9%)
TOTAL 24,333,312 16,879,616 −7,453,696 (−30.6%)

Debug:

Assembly Before After Saved
Uno.dll (Uno.UWP) 11,219,968 4,443,136 −6,776,832 (−60.4%)
Uno.UI.dll 16,024,064 15,517,184 −506,880 (−3.2%)
Uno.UI.Composition.dll 568,320 406,016 −162,304 (−28.6%)
Uno.Foundation.dll 227,328 222,720 −4,608 (−2.0%)
Uno.UI.Dispatching.dll 35,328 31,744 −3,584 (−10.1%)
TOTAL 28,075,008 20,620,800 −7,454,208 (−26.6%)

Combined: −7.45 MB across the five assemblies — −30.6% in Release, −26.6% in Debug. The absolute saving is the same in both configs (the #US heap is unaffected by IL optimization); the percentage is higher in Release because the assemblies are otherwise smaller. Uno.dll alone drops ~61%. These are unstripped builds — trimmed Release/AOT apps benefit before trimming even runs.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — N/A: representation-only refactor of generated code; validated by clean Skia builds (Debug + Release) of all five framework assemblies and before/after size measurement
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — N/A
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

Copilot AI review requested due to automatic review settings May 14, 2026 08:56

Copilot AI 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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund enabled auto-merge May 14, 2026 09:35
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

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

@MartinZikmund
MartinZikmund merged commit f417f87 into master May 14, 2026
44 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/usheap branch May 14, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DevLoop] Uno.dll's #US heap size is very large

5 participants