Skip to content

Commit f9e9563

Browse files
[One .NET] Profiled AOT support
Fixes: dotnet#6053 This is still WIP. Still a few pieces missing on the dotnet/runtime to enable this: dotnet/runtime#56989 We will need a `libmono-profiler-aot.so` from dotnet/runtime to be able to record AOT profiles. For now, I could: 1. Use the `startup.aotprofile` we're already shipping in "legacy" Xamarin.Android. 2. Pass this in when `$(AndroidEnableProfiledAot)` is `true`. ~~ Results ~~ All tests: 1. Were running on a [Google Pixel 5][0], and 2. Enabled two architectures, arm64 and x86, and 3. **AOT time** was average of 10 runs with `-c Release -p:RunAOTCompilation=true`, with the`Activity: Displayed` time 4. **Profiled AOT time** was average of 10 runs with `-c Release -p:RunAOTCompilation=true -p:AndroidEnableProfiledAot=true` with the `Activity: Displayed` time. | Test | AOT time | Profiled AOT time | AOT apk size | Profiled AOT apk size | | ------------------- | ------------: | ----------------: | ------------: | --------------------: | | [HelloAndroid][1] | 00:00:00.246 | 00:00:00.288 | 12,151,755 | 9,161,675 | | [HelloMaui][2] | 00:00:00.619 | 00:00:01.131 | 43,442,233 | 19,992,633 | From these results, we see that Profiled AOT is AOT'ing *some* of the assemblies. We are not getting the best startup time yet, because some methods are still using the JIT: 08-06 14:12:34.985 30817 30817 D Mono : AOT: FOUND method Android.Runtime.JNIEnv:NewGlobalRef (intptr) [0x7ae3c8c620 - 0x7ae3c8c6a0 0x7ae3c9849c] 08-06 14:12:34.985 30817 30817 D Mono : AOT: NOT FOUND: intptr:op_Explicit (intptr). 08-06 14:12:34.985 30817 30817 D Mono : AOT: NOT FOUND: intptr:op_Explicit (int). 08-06 14:12:34.986 30817 30817 D Mono : AOT: FOUND method System.WeakReference`1:.ctor (T,bool) [0x7ae3d8c580 - 0x7ae3d8c5d0 0x7ae3ddaec1] 08-06 14:12:34.986 30817 30817 D Mono : AOT: FOUND method System.WeakReference`1:Create (T,bool) [0x7ae3d8c4c0 - 0x7ae3d8c580 0x7ae3ddaebd] 08-06 14:12:34.986 30817 30817 D Mono : AOT: NOT FOUND: System.Runtime.InteropServices.GCHandle:Alloc (object,System.Runtime.InteropServices.GCHandleType). 08-06 14:12:34.986 30817 30817 D Mono : AOT: NOT FOUND: System.Runtime.InteropServices.GCHandle:Alloc (object,System.Runtime.InteropServices.GCHandleType). 08-06 14:12:34.986 30817 30817 D Mono : AOT: NOT FOUND: System.Runtime.InteropServices.GCHandle:.ctor (object,System.Runtime.InteropServices.GCHandleType). Overall, seems promising, though. [0]: store.google.com/us/product/pixel_5_specs?hl=en-US [1]: dotnet/maui-samples@7144604/HelloAndroid [2]: dotnet/maui-samples@7144604/HelloMaui
1 parent 9af3732 commit f9e9563

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ core workload SDK packs imported by WorkloadManifest.targets.
7474
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\Sdk\**" PackagePath="Sdk" />
7575
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Microsoft.Android.Sdk.ILLink\PreserveLists\**" PackagePath="PreserveLists" />
7676
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\**" PackagePath="targets" />
77+
<_PackageFiles Include="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\startup.aotprofile" PackagePath="targets" />
7778
<_PackageFiles Include="$(IntermediateOutputPath)UnixFilePermissions.xml" PackagePath="data" Condition=" '$(HostOS)' != 'Windows' " />
7879
<None Include="$(MSBuildThisFileDirectory)SignList.xml" CopyToOutputDirectory="PreserveNewest" />
7980
</ItemGroup>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Aot.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ They run in a context of an inner build with a single $(RuntimeIdentifier).
6969
TempDirectory="$([MSBuild]::EnsureTrailingSlash($(_AotOutputDirectory)))%(FileName)"
7070
AotArguments="$(_AotArguments),temp-path=$([System.IO.Path]::GetFullPath(%(_MonoAOTAssemblies.TempDirectory)))"
7171
/>
72+
<_AotProfiles Include="$(MSBuildThisFileDirectory)startup.aotprofile" Condition=" '$(AndroidEnableProfiledAot)' == 'true' " />
7273
</ItemGroup>
7374
<MakeDir Directories="$(IntermediateOutputPath)aot\;@(_MonoAOTAssemblies->'%(TempDirectory)')" />
7475
<MonoAOTCompiler
7576
Assemblies="@(_MonoAOTAssemblies)"
7677
CompilerBinaryPath="$(_MonoAOTCompilerPath)"
78+
AotProfilePath="@(_AotProfiles)"
7779
DisableParallelAot="$(_DisableParallelAot)"
7880
LibraryFormat="So"
7981
Mode="$(AndroidAotMode)"

0 commit comments

Comments
 (0)