[Mono.Android] trimmer feature switches for DotNetRuntimeType#10296
Merged
jonathanpeppers merged 2 commits intomainfrom Jul 16, 2025
Merged
[Mono.Android] trimmer feature switches for DotNetRuntimeType#10296jonathanpeppers merged 2 commits intomainfrom
DotNetRuntimeType#10296jonathanpeppers merged 2 commits intomainfrom
Conversation
|
|
||
| [FeatureSwitchDefinition ($"{FeatureSwitchPrefix}{nameof (IsMonoRuntime)}")] | ||
| internal static bool IsMonoRuntime { get; } = | ||
| AppContext.TryGetSwitch ($"{FeatureSwitchPrefix}{nameof (IsMonoRuntime)}", out bool isEnabled) ? isEnabled : IsMonoRuntimeEnabledByDefault; |
Member
There was a problem hiding this comment.
I wonder if we should enforce that the feature switch is always set explicitly and throw if it isn't. I'm worried that we could introduce a regression and for example we would drop the Microsoft.Android.Runtime.RuntimeFeature.IsMonoRuntime on CoreCLR in the SDK and now both IsMonoRuntime and IsCoreClrRuntime would be true.
Member
Author
There was a problem hiding this comment.
I'll add something that throws on startup if both are set to true.
...ndroid.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.RuntimeConfig.targets
Outdated
Show resolved
Hide resolved
Context: #10198 (comment) `ManagedValueManager` is not currently trimmed away in Android apps running on Mono. We can make this happen by: * Remove `DotNetRuntimeType` enum * Introduce `RuntimeFeature.IsMonoRuntime` and `RuntimeFeature.IsCoreClrRuntime` * Set switches by default for each runtime: <ItemGroup> <RuntimeHostConfigurationOption Include="Microsoft.Android.Runtime.RuntimeFeature.IsMonoRuntime" Value="false" Trim="true" /> <RuntimeHostConfigurationOption Include="Microsoft.Android.Runtime.RuntimeFeature.IsCoreClrRuntime" Value="true" Trim="true" /> </ItemGroup> I have not yet seen a need within the code to introduce `RuntimeFeature.IsNativeAotRuntime`, but we could do so in the future. Currently, NativeAOT works via the other two runtime feature switches being `false` and then none of the problematic code paths are hit.
f615d39 to
d834c56
Compare
jonathanpeppers
commented
Jul 16, 2025
| } | ||
| }, | ||
| "PackageSize": 3148309 | ||
| "PackageSize": 3090965 |
Member
Author
There was a problem hiding this comment.
This looks like it solves the minor app size regression from:
The number we used to have was 3078677, but that could have moved around slightly from other changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: #10198 (comment)
ManagedValueManageris not currently trimmed away in Android apps running on Mono.We can make this happen by:
Remove
DotNetRuntimeTypeenumIntroduce
RuntimeFeature.IsMonoRuntimeandRuntimeFeature.IsCoreClrRuntimeSet switches by default for each runtime:
I have not yet seen a need within the code to introduce
RuntimeFeature.IsNativeAotRuntime, but we could do so in the future.Currently, NativeAOT works via the other two runtime feature switches being
falseand then none of the problematic code paths are hit.