Skip to content
New issue

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

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

Already on GitHub? # to your account

[Xamarin.Android.Build.Tasks] introduce LlvmIrTypeCache #9251

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

jonathanpeppers
Copy link
Member

Context: https://github.com/dotnet/android/blob/main/Documentation/guides/tracing.md#how-to-dotnet-trace-a-build

Making a XAML or small C# change in a .NET MAUI project and running an incremental build, shows a reasonable amount of time spent in <GenerateJavaStubs /> -- even with a device attached.

If I attach dotnet trace to dotnet build, I can see time spent in:

117.08ms (2.20%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.GetNumberFormat(class System.Reflection.MemberInfo)
 82.33ms (1.60%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.IsNativePointerToPreallocatedBuffer(class System.Reflection.MemberInfo,unsigned int64&)
 29.30ms (0.56%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.UsesDataProvider(class System.Reflection.MemberInfo)
 17.49ms (0.33%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.PointsToSymbol(class System.Reflection.MemberInfo,class System.String&)
 15.03ms (0.29%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.IsNativePointer(class System.Reflection.MemberInfo)
  3.59ms (0.07%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.IsInlineArray(class System.Reflection.Membe

Where all of this time is spent in MemberInfoUtilities doing System.Reflection to lookup members such as:

[NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
public uint   mono_components_mask;

Introduce LlvmIrTypeCache to cache NativePointerAttribute or NativeAssemblerAttribute values based on MemberInfo. This cache will live the lifetime of a LlvmIrComposer instance, so future builds will not persist the cache.

With these changes in place, I see a modest improvement in an incremental build with a XAML change with an attached device (1 RID):

Before:
Task GenerateJavaStubs 1008ms
After:
Task GenerateJavaStubs 872ms

So, this probably improves things by about 100ms or so.

Context: https://github.com/dotnet/android/blob/main/Documentation/guides/tracing.md#how-to-dotnet-trace-a-build

Making a XAML or small C# change in a .NET MAUI project and running an
incremental build, shows a reasonable amount of time spent in
`<GenerateJavaStubs />` -- even with a device attached.

If I attach `dotnet trace` to `dotnet build`, I can see time spent in:

    117.08ms (2.20%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.GetNumberFormat(class System.Reflection.MemberInfo)
     82.33ms (1.60%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.IsNativePointerToPreallocatedBuffer(class System.Reflection.MemberInfo,unsigned int64&)
     29.30ms (0.56%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.UsesDataProvider(class System.Reflection.MemberInfo)
     17.49ms (0.33%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.PointsToSymbol(class System.Reflection.MemberInfo,class System.String&)
     15.03ms (0.29%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.IsNativePointer(class System.Reflection.MemberInfo)
      3.59ms (0.07%) xamarin.android.build.tasks!Xamarin.Android.Tasks.LLVMIR.MemberInfoUtilities.IsInlineArray(class System.Reflection.Membe

Where all of this time is spent in `MemberInfoUtilities` doing
System.Reflection to lookup members such as:

    [NativeAssembler (NumberFormat = LLVMIR.LlvmIrVariableNumberFormat.Hexadecimal)]
    public uint   mono_components_mask;

Introduce `LlvmIrTypeCache` to cache `NativePointerAttribute` or
`NativeAssemblerAttribute` values based on `MemberInfo`. This cache
will live the lifetime of a `LlvmIrComposer` instance, so future
builds will not persist the cache.

With these changes in place, I see a modest improvement in an
incremental build with a XAML change with an attached device (1 RID):

    Before:
    Task GenerateJavaStubs 1008ms
    After:
    Task GenerateJavaStubs 872ms

So, this probably improves things by about 100ms or so.
@jonathanpeppers jonathanpeppers merged commit c77c22c into dotnet:main Aug 28, 2024
57 checks passed
@jonathanpeppers jonathanpeppers deleted the LlvmIrTypeCache branch August 28, 2024 14:32
@github-actions github-actions bot locked and limited conversation to collaborators Sep 29, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants