Skip to content

[Java.Interop.Tools.TypeNameMappings] improve ToJniNameFromAttributesForAndroid #1064

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

Merged

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Dec 7, 2022

Reviewing dotnet-trace output:

dotnet trace collect --format speedscope -- C:\src\xamarin-android\bin\Release\dotnet\dotnet.exe build -bl --no-restore bar.csproj

On a dotnet new maui application, I noticed:

79.40ms java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniNameFromAttribute

This method just appears to be called a lot, and so things I changed:

  • Check type.HasCustomAttributes, attributeType.HasInterfaces, and attr.HasProperties where appropriate.

  • Unroll the System.Linq usage one level, and use plain foreach

  • Create a IsIJniNameProviderAttribute method that checks against a list of known attribute types as a "fast path".

  • The "slow path" can continue to check for the IJniNameProviderAttribute interface

Other changes:

  • Delete #region!

  • Some places were not actually correct, and were returning null where they should continue; instead.

After these changes, I get:

51.64ms java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniNameFromAttribute

This should save ~27ms on incremental builds of the dotnet new maui project template and likely even more on larger projects.

…sForAndroid`

Reviewing `dotnet-trace` output:

    dotnet trace collect --format speedscope -- C:\src\xamarin-android\bin\Release\dotnet\dotnet.exe build -bl --no-restore bar.csproj

On a `dotnet new maui` application, I noticed:

    79.40ms java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniNameFromAttribute

This method just appears to be called *a lot*, and so things I changed:

* Check `type.HasCustomAttributes`, `attributeType.HasInterfaces`, and
  `attr.HasProperties` where appropriate.

* Unroll the `System.Linq` usage one level, and use plain `foreach`

* Create a `IsIJniNameProviderAttribute` method that checks against a
  list of known attribute types as a "fast path".

* The "slow path" can continue to check for the
  `IJniNameProviderAttribute` interface

Other changes:

* Delete `#region`!

* Some places were not actually correct, and were returning `null`
  where they should `continue;` instead.

After these changes, I get:

    51.64ms (1.2%)	0.13ns (<0.01%)	java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniNameFromAttribute

This should save ~27ms on incremental builds of the `dotnet new maui`
project template and likely even more on larger projects.
@jonpryor jonpryor merged commit 8ab9d33 into dotnet:main Dec 8, 2022
@jonathanpeppers jonathanpeppers deleted the ToJniNameFromAttributesForAndroid branch December 8, 2022 23:38
jonpryor pushed a commit to dotnet/android that referenced this pull request Dec 12, 2022
Changes: dotnet/java-interop@3a9f770...149d70f

  * dotnet/java-interop@149d70fe: [generator] Refactor enum writing to use SourceWriters (dotnet/java-interop#1063)
  * dotnet/java-interop@c2daa9f0: [Java.Interop.Tools.Cecil] DirectoryAssemblyResolver & File.Exists() (dotnet/java-interop#1065)
  * dotnet/java-interop@8ab9d33a: [Java.Interop.Tools.TypeNameMappings] improve `ToJniNameFromAttributesForAndroid` (dotnet/java-interop#1064)
  * dotnet/java-interop@09f8da26: [JavaCallableWrappers] avoid `string.Format()` (dotnet/java-interop#1061)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
jonathanpeppers added a commit that referenced this pull request Jan 5, 2023
…sForAndroid` (#1064)

Reviewing `dotnet-trace` output:

	dotnet trace collect --format speedscope -- C:\src\xamarin-android\bin\Release\dotnet\dotnet.exe build -bl --no-restore bar.csproj

On a `dotnet new maui` application, I noticed:

	79.40ms java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniNameFromAttribute

This method just appears to be called *a lot*, and so things I changed:

  * Check `type.HasCustomAttributes`, `attributeType.HasInterfaces`,
    and `attr.HasProperties` where appropriate.

  * Unroll the `System.Linq` usage one level, and use plain `foreach`

  * Create a `IsIJniNameProviderAttribute` method that checks against
    a list of known attribute types as a "fast path".

  * The "slow path" can continue to check for the
    `IJniNameProviderAttribute` interface

Other changes:

  * Delete `#region`!

After these changes, I get:

	51.64ms (1.2%)	0.13ns (<0.01%)	java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniNameFromAttribute

This should save ~27ms on incremental builds of the `dotnet new maui`
project template and likely even more on larger projects.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants