Skip to content

Support for Android "Profiled AOT" in .NET 6 #56989

Closed

Description

@jonathanpeppers

This feature in Xamarin.Android is also known as "Startup Tracing":

https://devblogs.microsoft.com/xamarin/faster-android-startup-times-with-startup-tracing/

Yet another name for this might be "profile guided optimization".

For .NET 6, we'd like users be able to do something like the following in Release builds:

<RunAOTCompilation>true</RunAOTCompilation>
<UseProfiledAOT>true</UseProfiledAOT>

This would use a built-in profile that the Android workload provides as well as the .NET MAUI workload. Recording a custom profile for a developer's app is probably not something we need in .NET 6. However, the Android & .NET MAUI teams would need to be able to record profiles. .NET MAUI's startup path is still quite a bit in flux, so ideally we would be automate the creation of the built-in MAUI profile.

There are a few pieces missing from dotnet/runtime at the moment:

  1. libmono-profiler-aot.so
  2. aprofutil
  3. MonoAOTCompiler.AotProfilePath only accepts 1 value:

/// <summary>
/// File to use for profile-guided optimization, *only* the methods described in the file will be AOT compiled.
/// </summary>
public string? AotProfilePath { get; set; }

For .NET 6, I think we can take a simple approach:

  1. Build & ship libmono-profiler-aot.so in the Android runtime packs.
  2. The Android workload can ship a aprofutil from mono/mono. We can emit warnings that mention recording custom AOT profiles is an experimental feature.
  3. We can emit profile-only,profile=foo.aprof for %(AotArguments) in the Android MSBuild targets until there is a different way.

These would get us by for now.

In the long run, recording custom AOT profiles might be something that dotnet-trace / diagnostics should support.

Activity

  1. ghost added
    untriaged
    on Aug 6, 2021
  2. added and removed
    untriaged
    on Aug 6, 2021
  3. added this to the 6.0.0 milestone on Aug 6, 2021
  4. akoeplinger commented on Aug 6, 2021

    @akoeplinger
    Member

    So we need to do two things:

  5. steveisok commented on Aug 10, 2021

    @steveisok
    Member

    So we need to do two things:

    • enable build of libmono-profiler-aot.so in mono.proj (it's already done for Browser)

    I'm assuming we would want to include this file in the aot pack, correct?

  6. jonathanpeppers commented on Aug 10, 2021

    @jonathanpeppers
    MemberAuthor

    @steveisok it could got in the AOT pack, but you would need an item group like this:

    <ItemGroup>
    <MonoAotCrossCompiler Include="$(MSBuildThisFileDirectory)..\tools\mono-aot-cross${ExeSuffix}" RuntimeIdentifier="${TargetRid}" />
    </ItemGroup>

    Then the Android workload could include this file in apps when needed.

  7. 5 remaining items

  8. jonathanpeppers commented on Aug 13, 2021

    @jonathanpeppers
    MemberAuthor

    I got libmono-profiler-aot.so added to the Microsoft.NETCore.App.Runtime.AOT.[host-rid].Cross.[target-rid] packs, and added a new item group for its path.

    But the problem is these packs are only imported when $(RunAOTCompilation) is true:

    <ImportGroup Condition="'$(TargetPlatformIdentifier)' == 'android' and '$(RunAOTCompilation)' == 'true'">
    <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x86" />
    <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-x64" />
    <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-arm" />
    <Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.android-arm64" />
    </ImportGroup>

    When users record a profile, they won't be using AOT. Generally you just run a Debug build to record a profile, and $(RunAOTCompilation) would be blank.

    Should I add this file to the runtime packs instead? And I would add something to exclude it in the Android workload for most builds? Similar to a Mono component, I guess?

  9. ghost added
    in-pr
    on Aug 16, 2021
  10. added a commit that references this issue on Sep 1, 2021
  11. modified the milestones: 6.0.0, 7.0.0 on Sep 27, 2021
  12. steveisok commented on Sep 27, 2021

    @steveisok
    Member

    Moving the milestone to .NET 7 as we plan on trying to streamline w/ diagnostics.

  13. ghost removed
    in-pr
    on Oct 12, 2021
  14. added a commit that references this issue on May 5, 2022
  15. steveisok commented on Aug 2, 2022

    @steveisok
    Member

    In .NET 7, with #70194, #70851, and #68571, we have a replacement for libmono-profiler-aot.so and aprofutil.

  16. ghost locked as resolved and limited conversation to collaborators on Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions