8000 [CoreCLR] Remove unused marshal methods code by grendello · Pull Request #10180 · dotnet/android · GitHub
[go: up one dir, main page]

Skip to content

Conversation

grendello
Copy link
Contributor
@grendello grendello commented Jun 9, 2025

Our build process targetting CoreCLR generated marshal methods code that is
only used by our MonoVM runtime. The native code included marshal methods and
class n 8000 ames, as well as assembly image cache which is not supported on CoreCLR.

All of the above data were stored as pointers in the resulting libxamarin-app.so,
each pointer being a relocation that has to be fixed up by the system dynamic linker
at application load time. The more relocations exist across the .so file, the more
of it the linker has to actually read into memory (instead of just mmapping it and
lazily loading whenever/if the code/data in that section is used).

This PR removes all of that code from the CoreCLR version of libxamarin-app.so,
together with a number of native structs supporting the data.

Testing the changes on a dotnet new maui -sc application, we can see the following
savings:

  • Number of relocations in libxamarin-app.so drops from 903 to 394 entries
  • libxamarin-app.so size drops from:
    • arm64: 443648 to 368832 bytes (16.9%)
    • x64: 438856 to 360464 bytes (17.9%)

Testing the above MAUI app performance on Pixel 8, we can also see a tiny startup
time decrease by 0.71%. On slower devices and with bigger applications the startup
performance improvement will be bigger (the slower the device's storage, the bigger
time savings)

@grendello grendello force-pushed the dev/grendel/clr-host-marshalmethods-cleanup branch from df5f231 to 73200bd Compare June 12, 2025 08:52
@grendello grendello force-pushed the dev/grendel/clr-host-marshalmethods-cleanup branch from 73200bd to c101949 Compare June 12, 2025 16:35
@grendello grendello marked this pull request as ready for review June 12, 2025 16:48
@grendello grendello requested a review from Copilot June 12, 2025 16:49
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes unused CoreCLR-specific marshal methods and related data from the native runtime to reduce binary size and startup relocations, and refactors the MSBuild tasks to cleanly separate MonoVM vs. CoreCLR code generation.

  • Eliminate CoreCLR marshal-method tables and stubs from native sources
  • Split MarshalMethodsNativeAssemblyGenerator into MonoVM and CoreCLR subclasses
  • Update the MSBuild task to dispatch based on an AndroidRuntime parameter

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/native/common/include/runtime-base/timing-internal.hh Simplify timing log label from "; elapsed exp:" to "; elapsed:"
src/native/clr/xamarin-app-stub/application_dso_stub.cc Remove #if RELEASE marshal-methods data structures
src/native/clr/include/xamarin-app.hh Drop marshal-methods declarations under CoreCLR
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Add AndroidRuntime attribute to GenerateNativeMarshalMethodSources
src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGeneratorMonoVM.cs Introduce MonoVM-specific generator subclass
src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGeneratorCoreCLR.cs Introduce CoreCLR-specific generator subclass
src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs Refactor base generator to abstract and move CoreCLR/MonoVM logic
src/Xamarin.Android.Build.Tasks/Tasks/GenerateNativeMarshalMethodSources.cs Dispatch generator creation via AndroidRuntime switch
Comments suppressed due to low confidence (4)

src/Xamarin.Android.Build.Tasks/Tasks/GenerateNativeMarshalMethodSources.cs:69

  • The switch cases reference Tasks.AndroidRuntime.MonoVM and Tasks.AndroidRuntime.CoreCLR, but Tasks isn’t an existing alias here. Use the AndroidRuntime enum directly (e.g. AndroidRuntime.MonoVM) or add a proper using so the enum resolves correctly.
MarshalMethodsNativeAssemblyGenerator marshalMethodsAsmGen = androidRuntime switch {

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs:135

  • List fields should be initialized with a new List<uint>() instead of [], which is valid only for array literals. Otherwise this will not compile.
public List<uint> Keys32 = [];

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsNativeAssemblyGenerator.cs:140

  • Similarly, initialize Keys64 using new List<ulong>() instead of [] to avoid compile errors.
public List<ulong> Keys64 = [];

src/Xamarin.Android.Build.Tasks/Tasks/GenerateNativeMarshalMethodSources.cs:33

  • [nitpick] Indent this property to match the other task properties for consistent formatting.
        public string AndroidRuntime { get; set; } = "";

MarshalMethodsNativeAssemblyGenerator marshalMethodsAsmGen = androidRuntime switch {
Tasks.AndroidRuntime.MonoVM => MakeMonoGenerator (),
Tasks.AndroidRuntime.CoreCLR => MakeCoreCLRGenerator (),
_ => throw new NotSupportedException ($"Internal error: unsupported runtime type '{androidRuntime}'")
Copy link
Member

Choose a reason for hiding this comment

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

As long as none of the NativeAOT tests get here, this looks good. 👍

@jonathanpeppers jonathanpeppers enabled auto-merge (squash) June 12, 2025 20:38
@jonathanpeppers jonathanpeppers merged commit 96a73e6 into main Jun 12, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/grendel/clr-host-marshalmethods-cleanup branch June 12, 2025 21:22
@github-actions github-actions bot locked and limited conversation to collaborators Jul 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0