[net11.0] Fully trim assemblies in R2R image when using SdkOnly link mode in Debug#24909
[net11.0] Fully trim assemblies in R2R image when using SdkOnly link mode in Debug#24909kotlarmilos wants to merge 2 commits intonet11.0from
Conversation
…mode When FilterReadyToRunAssemblies is active (Debug builds with CoreCLR R2R), only NuGet/framework assemblies enter the R2R composite image while user assemblies run interpreted for debugging. Currently, with the default SdkOnly link mode, framework assemblies are only trimmed if they have IsTrimmable=true metadata. This leaves some assemblies untrimmed in the R2R image, increasing bundle size. Add _SetR2RAssemblyTrimMode target that forces TrimMode=link on all NuGet/framework assemblies entering the R2R image and TrimMode=copy on user assemblies when _LinkMode is SdkOnly. Results (MAUI template, Debug, CoreCLR, iOS arm64): - Bundle size: 140.42 MB -> 112.66 MB (-27.76 MB, -19.8%) - Startup: 183.89 ms -> 172.25 ms (-11.64 ms, -6.3%) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #b9a2ea1] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #b9a2ea1] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ [CI Build #b9a2ea1] Build passed (Build macOS tests) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🔥 [CI Build #b9a2ea1] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 1 tests failed, 154 tests passed. Failures❌ Tests on macOS Tahoe (26) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
If a framework assembly doesn't have If a framework assembly is indeed trimmable, then it seems like the better solution would be to set |
|
Also which assemblies are these? |
|
The assemblies in the R2R image that don't have IsTrimmable=true are:
I initially misunderstood SdkOnly. I thought it only trimmed SDK/framework assemblies, not all assemblies with IsTrimmable=true. Since the default IsTrimmable=false, I assume that many third-party nuget packs don't have it explicitly set, but might be wrong.
What do you have in mind here? |
Note that IsTrimmable can be set as an assembly attribute as well: https://github.com/dotnet/runtime/blob/main/docs/design/tools/illink/trimmed-assemblies.md#net-6 And looking at System.Private.CoreLib.dll, it has: [assembly: System.Reflection.AssemblyMetadata ("IsTrimmable", "True")]so it's strange to see SPC.dll in this list.
Set the same AssemblyMetadata attribute on the MAUI assemblies as well (if they're indeed trimmable). This has a few additional advantages:
That's a historical accident: "SdkOnly" is old, and before .NET that's exactly what it meant: trim the framework assemblies only. In .NET things are somewhat different (to start: what's a "framework assembly" exactly?), so we changed the meaning a little bit to be "all assemblies that declare themselves to be trimmable", which was both close enough to the truth (only BCL assemblies declared themselves to be trimmmable, at least at first), and it's also close in spirit (trim all assemblies that are known to trimmer safe). |
|
Thanks. Closing this PR in favour of dotnet/maui#34573 |
When
FilterReadyToRunAssembliesis active (Debug builds with CoreCLR R2R), only NuGet/framework assemblies enter the R2R composite image while user assemblies run interpreted for debugging.Currently, with the default
SdkOnlylink mode, framework assemblies are only trimmed if they haveIsTrimmable=truemetadata. This leaves some assemblies untrimmed in the R2R image, increasing bundle size unnecessarily since these assemblies won't be used for debugging.This change adds a
_SetR2RAssemblyTrimModetarget that, when_LinkMode == 'SdkOnly'and R2R filtering is active:TrimMode=linkandIsTrimmable=trueon all NuGet/framework assemblies (entering R2R image)TrimMode=copyon user assemblies (interpreted, kept intact for debugging)If the user explicitly sets
FullorNonelink mode, their choice is respected.Results (MAUI template app, Debug, CoreCLR, iOS arm64):