Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] add AOT profile for .NET MAUI #2496

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

jonathanpeppers
Copy link
Member

Context: dotnet/android@3e699d6
Context: https://github.com/jonathanpeppers/android-profiled-aot

Add a maui.aotprofile, and bundle with .NET MAUI. Recording custom
profiles is not supported by dotnet/runtime, but it can be done
following the instructions in the jonathanpeppers/android-profiled-aot
repo.

To ship an AOT Profile for MAUI:

  1. Default $(AndroidUseDefaultAotProfile) to false, so the plain
    Android profile is not used. The default Android profile only
    contains methods in AndroidX, Mono.Android.dll, Java.Interop.dll, etc.
  2. Default @(AndroidAotProfile) to maui.aotprofile, unless
    $(MauiUseDefaultAotProfile) is false.

Profile Contents

Modules:
    EA3844FC-D728-4D48-9598-1C93505E4623 System.Private.CoreLib
    2CC403AF-60DC-48A9-9B69-FF254277AEA0 Mono.Android
    92FF7068-2EA9-4681-B340-44E91077417A Java.Interop
    3E65EB5C-02E9-4DE5-AC19-B2F2BAF2857B Microsoft.Maui.Essentials
    21CF52B7-0256-4838-848C-DA026B2F1789 Xamarin.AndroidX.Core
    35358E14-E381-4472-858E-ABFD81B3517C Microsoft.Maui
    5A334DAA-789C-421E-9B20-F1B66879BF49 Microsoft.Extensions.Hosting
    C3C04DA6-9F0C-48FD-83EA-115CB6076248 Microsoft.Extensions.DependencyInjection
    1CC454CF-BE07-4D95-B1E7-3EFC458F943C Microsoft.Extensions.DependencyInjection.Abstractions
    229E3EBA-F00D-40DF-BEB8-4C16CB84DE98 Microsoft.Extensions.Configuration.Abstractions
    CCAA9BA7-D5D3-47EC-8FBB-DED7D6FC2143 Microsoft.Extensions.Configuration
    981BD5D2-69A5-4C0B-A258-50BB28365D5B Microsoft.Extensions.Primitives
    C674A867-6352-482C-9A7A-0272480711AC Microsoft.Extensions.Hosting.Abstractions
    1D537869-4CC1-4E6D-B0BF-6ABEA40ADF8B Microsoft.Extensions.Configuration.FileExtensions
    3C68719B-EA9F-48EC-86D7-2EE85CDA2272 Microsoft.Extensions.FileProviders.Physical
    0D1C05F9-FFB8-4A75-A24E-6C17893B53F7 System.Linq
    DCE2ADDD-008E-43B4-B1D6-3CCA222678FF Microsoft.Extensions.Logging
    C9E0059C-3CE2-4B91-BE1D-808EF93495C3 Microsoft.Extensions.Options
    8A3A36B0-0D51-4CF6-A5F0-2E1EF0A01648 Microsoft.Extensions.Logging.Abstractions
    DDC70C0B-3BAA-4844-8401-65EA77FBDDDC Microsoft.Extensions.Logging.Configuration
    28AB2955-BA00-4EAC-90B6-4E31F4826D75 Microsoft.Extensions.Options.ConfigurationExtensions
    BC607A7F-080C-424F-8A37-011B30F6DE55 Microsoft.Extensions.Logging.Console
    1BDE760B-6269-47BC-9BF5-6B44DC9CC032 Microsoft.Extensions.Logging.Debug
    9D7AA4B2-70B7-4329-A099-BE5F3B8FE0A4 Microsoft.Extensions.Logging.EventSource
    DF5F5616-FA06-46C0-8025-6DA20BB34CEC Microsoft.Maui.Controls.Compatibility
    63B89754-AAED-4092-9FDE-E50EB969DE1B MauiApp1
    1F1E6C61-F9BC-488D-9EC4-335D0D5A0800 Microsoft.Maui.Graphics
    38104510-26A0-4B40-8542-80153806B860 System.Diagnostics.DiagnosticSource
    F7E05AD1-4195-4539-B3AD-487030D94748 System.Collections.Concurrent
    2795C489-C1E7-40BC-ACF2-B84C11F67B47 Microsoft.Extensions.Configuration.Binder
    F26C0583-5BFE-4B78-BC65-84547BAA9F75 System.Runtime.InteropServices.RuntimeInformation
    404F6169-7356-4D95-BD9A-3A5C7D88BD6E System.Console
    CD148B87-3553-48A2-8853-CEC72437F2A2 Microsoft.Maui.Controls
    99F9B89D-EF4E-4F6B-B785-56AFD6E37113 Microsoft.Maui.Controls.Xaml
    1B55562C-5DD7-4779-8473-8B4558C8D065 System.ComponentModel.TypeConverter
    43402C13-3212-4B9C-8A1C-0BA8C6AC6F29 System.ObjectModel
    8766384A-BB06-42DA-810C-B5B2B0D7C971 System.Private.Xml
    82E0E2F3-002E-4780-BEC2-E230299A5ED2 System.Private.Uri
    7CEE6098-BE9F-4043-B35A-B8B0684EF0CB Xamarin.AndroidX.AppCompat
    20D1FBB8-829A-4618-8E82-8047C8827EA8 Xamarin.AndroidX.Fragment
    CC363D7A-9CDB-4999-9E10-279412B14A1B Xamarin.AndroidX.Activity
    008C0F24-5014-4D41-AAB9-DDFCEA59E171 Xamarin.Google.Android.Material
Summary:
    Modules:         42
    Types:        1,234
    Methods:      5,030

Results

All tests:

  1. Were running on a Google Pixel 5, and
  2. Enabled two architectures, arm64 and x86, and
  3. JIT time was average of 10 runs with -c Release, no AOT
  4. AOT time was average of 10 runs with -c Release -p:RunAOTCompilation=true, with theActivity: Displayed time
  5. Profiled AOT time was average of 10 runs with -c Release -p:RunAOTCompilation=true -p:AndroidEnableProfiledAot=true with
    the Activity: Displayed time.
AndroidApp1 MauiApp1
JIT startup time (s) 00:00.4387 00:01.4205
AOT startup time (vs. JIT) 00:00.3317 ( 76%) 00:00.7285 ( 51%)
Profiled AOT startup time (vs. JIT) 00:00.3093 ( 71%) 00:00.7098 ( 50%)
JIT .apk size (B) 9,155,954 17,435,225
AOT .apk size (vs. JIT) 12,755,672 (139%) 44,751,651 (257%)
Profiled AOT .apk size (vs. JIT) 9,777,880 (107%) 23,210,787 (133%)

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)
  • Targets a single property for a single control (or intertwined few properties)
  • Adds the property to the appropriate interface
  • Avoids any changes not essential to the handler property
  • Adds the mapping to the PropertyMapper in the handler
  • Adds the mapping method to the Android, iOS, and Standard aspects of the handler
  • Implements the actual property updates (usually in extension methods in the Platform section of Core)
  • Tags ported renderer methods with [PortHandler]
  • Adds an example of the property to the sample project (MainPage)
  • Adds the property to the stub class
  • Implements basic property tests in DeviceTests

Does this PR touch anything that might affect accessibility?

No

@jonathanpeppers
Copy link
Member Author

Hmm, there is no Android NDK on CI here:

 error XA5104: Could not locate the Android NDK. Please make sure the Android NDK is installed in the Android SDK Manager, or if using a custom NDK path, please ensure the $(AndroidNdkDirectory) MSBuild property is set to the custom path.

Need to look into this.

Context: dotnet/android@3e699d6
Context: https://github.com/jonathanpeppers/android-profiled-aot

Add a `maui.aotprofile`, and bundle with .NET MAUI. Recording custom
profiles is not supported by dotnet/runtime, but it can be done
following the instructions in the jonathanpeppers/android-profiled-aot
repo.

To ship an AOT Profile for MAUI:

1. Default `$(AndroidUseDefaultAotProfile)` to `false`, so the plain
   Android profile is not used. The default Android profile only
   contains methods in AndroidX, Mono.Android.dll, Java.Interop.dll, etc.
2. Default `@(AndroidAotProfile)` to `maui.aotprofile`, unless
   `$(MauiUseDefaultAotProfile)` is `false`.

~~ Profile Contents ~~

    Modules:
        EA3844FC-D728-4D48-9598-1C93505E4623 System.Private.CoreLib
        2CC403AF-60DC-48A9-9B69-FF254277AEA0 Mono.Android
        92FF7068-2EA9-4681-B340-44E91077417A Java.Interop
        3E65EB5C-02E9-4DE5-AC19-B2F2BAF2857B Microsoft.Maui.Essentials
        21CF52B7-0256-4838-848C-DA026B2F1789 Xamarin.AndroidX.Core
        35358E14-E381-4472-858E-ABFD81B3517C Microsoft.Maui
        5A334DAA-789C-421E-9B20-F1B66879BF49 Microsoft.Extensions.Hosting
        C3C04DA6-9F0C-48FD-83EA-115CB6076248 Microsoft.Extensions.DependencyInjection
        1CC454CF-BE07-4D95-B1E7-3EFC458F943C Microsoft.Extensions.DependencyInjection.Abstractions
        229E3EBA-F00D-40DF-BEB8-4C16CB84DE98 Microsoft.Extensions.Configuration.Abstractions
        CCAA9BA7-D5D3-47EC-8FBB-DED7D6FC2143 Microsoft.Extensions.Configuration
        981BD5D2-69A5-4C0B-A258-50BB28365D5B Microsoft.Extensions.Primitives
        C674A867-6352-482C-9A7A-0272480711AC Microsoft.Extensions.Hosting.Abstractions
        1D537869-4CC1-4E6D-B0BF-6ABEA40ADF8B Microsoft.Extensions.Configuration.FileExtensions
        3C68719B-EA9F-48EC-86D7-2EE85CDA2272 Microsoft.Extensions.FileProviders.Physical
        0D1C05F9-FFB8-4A75-A24E-6C17893B53F7 System.Linq
        DCE2ADDD-008E-43B4-B1D6-3CCA222678FF Microsoft.Extensions.Logging
        C9E0059C-3CE2-4B91-BE1D-808EF93495C3 Microsoft.Extensions.Options
        8A3A36B0-0D51-4CF6-A5F0-2E1EF0A01648 Microsoft.Extensions.Logging.Abstractions
        DDC70C0B-3BAA-4844-8401-65EA77FBDDDC Microsoft.Extensions.Logging.Configuration
        28AB2955-BA00-4EAC-90B6-4E31F4826D75 Microsoft.Extensions.Options.ConfigurationExtensions
        BC607A7F-080C-424F-8A37-011B30F6DE55 Microsoft.Extensions.Logging.Console
        1BDE760B-6269-47BC-9BF5-6B44DC9CC032 Microsoft.Extensions.Logging.Debug
        9D7AA4B2-70B7-4329-A099-BE5F3B8FE0A4 Microsoft.Extensions.Logging.EventSource
        DF5F5616-FA06-46C0-8025-6DA20BB34CEC Microsoft.Maui.Controls.Compatibility
        63B89754-AAED-4092-9FDE-E50EB969DE1B MauiApp1
        1F1E6C61-F9BC-488D-9EC4-335D0D5A0800 Microsoft.Maui.Graphics
        38104510-26A0-4B40-8542-80153806B860 System.Diagnostics.DiagnosticSource
        F7E05AD1-4195-4539-B3AD-487030D94748 System.Collections.Concurrent
        2795C489-C1E7-40BC-ACF2-B84C11F67B47 Microsoft.Extensions.Configuration.Binder
        F26C0583-5BFE-4B78-BC65-84547BAA9F75 System.Runtime.InteropServices.RuntimeInformation
        404F6169-7356-4D95-BD9A-3A5C7D88BD6E System.Console
        CD148B87-3553-48A2-8853-CEC72437F2A2 Microsoft.Maui.Controls
        99F9B89D-EF4E-4F6B-B785-56AFD6E37113 Microsoft.Maui.Controls.Xaml
        1B55562C-5DD7-4779-8473-8B4558C8D065 System.ComponentModel.TypeConverter
        43402C13-3212-4B9C-8A1C-0BA8C6AC6F29 System.ObjectModel
        8766384A-BB06-42DA-810C-B5B2B0D7C971 System.Private.Xml
        82E0E2F3-002E-4780-BEC2-E230299A5ED2 System.Private.Uri
        7CEE6098-BE9F-4043-B35A-B8B0684EF0CB Xamarin.AndroidX.AppCompat
        20D1FBB8-829A-4618-8E82-8047C8827EA8 Xamarin.AndroidX.Fragment
        CC363D7A-9CDB-4999-9E10-279412B14A1B Xamarin.AndroidX.Activity
        008C0F24-5014-4D41-AAB9-DDFCEA59E171 Xamarin.Google.Android.Material
    Summary:
        Modules:         42
        Types:        1,234
        Methods:      5,030

~~ Results ~~

All tests:

 1. Were running on a [Google Pixel 5][0], and
 2. Enabled two architectures, arm64 and x86, and
 3. **JIT time** was average of 10 runs with `-c Release`, no AOT
 4. **AOT time** was average of 10 runs with `-c Release
    -p:RunAOTCompilation=true`, with the`Activity: Displayed` time
 5. **Profiled AOT time** was average of 10 runs with `-c Release
    -p:RunAOTCompilation=true -p:AndroidEnableProfiledAot=true` with
    the `Activity: Displayed` time.

|                                     |    [AndroidApp1][1] |     [MauiApp1][2] |
| ----------------------------------: | ------------------: | ----------------: |
|                JIT startup time (s) |   00:00.4387        | 00:01.4205        |
|          AOT startup time (vs. JIT) |   00:00.3317 ( 76%) | 00:00.7285 ( 51%) |
| Profiled AOT startup time (vs. JIT) |   00:00.3093 ( 71%) | 00:00.7098 ( 50%) |
|                 JIT `.apk` size (B) |    9,155,954        | 17,435,225        |
|           AOT `.apk` size (vs. JIT) |   12,755,672 (139%) | 44,751,651 (257%) |
|  Profiled AOT `.apk` size (vs. JIT) |    9,777,880 (107%) | 23,210,787 (133%) |

[0]: store.google.com/us/product/pixel_5_specs?hl=en-US
[1]: jonathanpeppers/android-profiled-aot@e48c6df/AndroidApp1
[2]: jonathanpeppers/android-profiled-aot@e48c6df/MauiApp1
@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Sep 16, 2021

I didn't add something to CI for this, because we'd need to download/install the Android NDK.

So I manually tested:

.\bin\dotnet\dotnet.exe build .\src\Controls\samples\Controls.Sample.Droid\Maui.Controls.Sample.Droid-net6.csproj -t:Run -c Release -p:AndroidEnableProfiledAot=true -p:RunAOTCompilation=true -bl -p:UseWorkload=true

I see in the .binlog:

AndroidAotProfile
    C:\Users\myuser\.nuget\packages\microsoft.maui.controls.build.tasks\6.0.100-dev\build\maui.aotprofile

The .apk comes out correct:

> ls .\src\Controls\samples\Controls.Sample.Droid\bin\Release\net6.0-android\com.microsoft.maui-Signed.apk
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         9/16/2021   2:41 PM       26440532 com.microsoft.maui-Signed.apk

@jonathanpeppers jonathanpeppers marked this pull request as ready for review September 16, 2021 22:07
@jonathanpeppers jonathanpeppers merged commit 7dcc01a into dotnet:main Sep 17, 2021
@jonathanpeppers jonathanpeppers deleted the android-profiled-aot branch September 17, 2021 13:34
@Redth Redth added this to the 6.0.101-preview.9 milestone Sep 27, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
@samhouts samhouts added the fixed-in-6.0.101-preview.10 Look for this fix in 6.0.101-preview.10! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-6.0.101-preview.10 Look for this fix in 6.0.101-preview.10!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants