[ios] Investigate stripping EntryPoint
strings from assemblies as a size optimization for Mono iOS applications
#21732
Labels
Milestone
Description
In .NET 9 we enabled managed-static registrar to be the default setting when targeting iOS platforms with Mono.
This change regressed MAUI sample application size when targeting iOS by
~2-3%
as reported in: #20174The reason for the regression is generating more managed code which needs to be AOT-compiled.
During some investigation I noticed that after we run ILStrip (Mono's size-optimization task which removes unneeded IL code from assemblies which are preserved mostly for metadata information and reflection support) we keep
UnmanagedCallersOnly
attributes data on methods which are generated for the new registrar, for example:Here we can see a size-saving opportunity, specifically in regard to
EntryPoint
values on UCO methods which are not needed or used during runtime.SIze-saving
By creating a simple
Mono.Cecil
task which strips out only custom attributes from methods defined on__Registrar_Callbacks__
types from stripped assemblies of the app, it has been estimated that with adotnet new maui
app and .NET 9 GA SDK we could save~2%
of the application size when using Mono with this approach.NOTE: The save saving is currently applicable only to Mono, as with Native AOT we do not need/keep managed assemblies in the application bundle.
Comparing managed-static registrar without and with UCO
EntryPoint
stripping with .NET 9 GAComparing static with managed-static registrar and UCO
EntryPoint
stripping with .NET 9 GASuch an improvement would make the app sizes between the new managed-static and the old static registrar almost identical.
Proposal
Investigate adapting https://github.com/dotnet/runtime/tree/e7d837da5b1aacd9325a8b8f2214cfaf4d3f0ff6/src/tasks/MonoTargetsTasks/ILStrip/AssemblyStripper
so that it strips out
EntryPoint
values on UCO methods introduced for managed-static registrar and measure the actual size saving.The text was updated successfully, but these errors were encountered: