dotnet / dotnet/android

TrimmerRootAssembly deoptimizes size of native AOT apps

Open
#10,672 1 comment 1 reaction 0 assignees View on GitHub
Area: App+Library Build needs-triage
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 19h
Merged PRs (30d)
252

Description

### Android framework version

Other

### Affected platform version

.NET 11

### Description

https://github.com/dotnet/android/blob/c4b72d3ee538256bd04b2384f92012dd8f0e7042/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets#L113-L114

This forces the compiler to consider everything that survived IL trimming as target of reflection. This is a big deoptimization. ILC has an internal/undocumented mode that does something similar (add `/p:IlcTrimMetadata=false` to `dotnet publish` and you'll get similar results to how an ILLinked IL-based app looks like under reflection). Adding this undocumented switch to a `dotnet new webapiaot` app doubles the size of the native AOT output, for example).

See also conversation around https://discord.com/channels/732297728826277939/732297837953679412/1444909702512119899 on discord.

We should work on ensuring this is not needed. Xamarin macios originally started with a similar TrimmerRootAssembly thing but it was removed before shipping.

The first step in getting rid of this should be to review all the `UnconditionalSuppressMessage` attributes in this repo.

I can help with this work.

Cc @sbomer FYI

### Steps to Reproduce

Build a native AOT android app.

### Did you find any workaround?

_No response_

### Relevant log output

```shell

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.