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

[Xamarin.Android.Build.Tasks] <GenerateJavaStubs/> only for MonoAndroid assemblies #2643

Merged

Conversation

jonathanpeppers
Copy link
Member

Currently the <GenerateJavaStubs/> MSBuild task will load and
iterate over NetStandard or PCL assemblies. It simply looks at all
items in @(_ResolvedUserAssemblies) and writes Java stubs if needed.

We could look at the TargetFrameworkIdentifier and only do this
work for MonoAndroid assemblies.

To make this work:

  • The <ResolveAssemblies/> MSBuild task needs to parse the
    TargetFrameworkIdentifier and add it to the item metadata for each
    assembly.
  • <GenerateJavaStubs/> should use a subset of
    @(_ResolvedUserAssemblies) where TargetFrameworkIdentifier is
    MonoAndroid.

Results:

Before
    First:       1200 ms  GenerateJavaStubs                          1 calls
    Incremental: 1047 ms  GenerateJavaStubs                          1 calls
After
    First:       1084 ms  GenerateJavaStubs                          1 calls
    Incremental:  868 ms  GenerateJavaStubs                          1 calls

This seems to save ~200ms in the Xamarin.Forms integration project in
this repo. Projects using lots of NetStandard/PCL assemblies should
see a bigger benefit.

@jonathanpeppers
Copy link
Member Author

Binlogs: logs.zip

var value = p.Value?.ToString ();
if (value != null && value.StartsWith ("MonoAndroid", StringComparison.Ordinal)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this original code of using value.StartsWith("MonoAndroid") -- though perhaps it should be extended to value.StartsWith("MonoAndroid,")? -- largely because I'm not sure about what are the requirements and constraints on framework names.

For example, if a "framework name" could contain a comma, the new approach of splitting on all commas may cause a "mismatch". Using StartsWith() against MonoAndroid, would alloy such fears.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After using IndexOf + Substring, I think it's still OK to just compare targetFrameworkIdentifier == "MonoAndroid":

//
// Summary:
//     Reports the zero-based index of the first occurrence of the specified string
//     in the current System.String object. A parameter specifies the type of search
//     to use for the specified string.
//
// Returns:
//     The index position of the value parameter if that string is found, or -1 if it
//     is not. If value is System.String.Empty, the return value is 0.
public int IndexOf (String value, StringComparison comparisonType);

It should be the first instance of , and targetFrameworkIdentifier will be everything before it.

…id assemblies

Currently the `<GenerateJavaStubs/>` MSBuild task will load and
iterate over NetStandard or PCL assemblies. It simply looks at all
items in `@(_ResolvedUserAssemblies)` and writes Java stubs if needed.

We could look at the `TargetFrameworkIdentifier` and *only* do this
work for `MonoAndroid` assemblies.

To make this work:

- The `<ResolveAssemblies/>` MSBuild task needs to parse the
  `TargetFrameworkIdentifier` and add it to the item metadata for each
  assembly.
- `<GenerateJavaStubs/>` should use a subset of
  `@(_ResolvedUserAssemblies)` where `TargetFrameworkIdentifier` is
  `MonoAndroid`.

Results:

    Before
        First:       1200 ms  GenerateJavaStubs                          1 calls
        Incremental: 1047 ms  GenerateJavaStubs                          1 calls
    After
        First:       1084 ms  GenerateJavaStubs                          1 calls
        Incremental:  868 ms  GenerateJavaStubs                          1 calls

This seems to save ~200ms in the Xamarin.Forms integration project in
this repo. Projects using lots of NetStandard/PCL assemblies should
see a bigger benefit.
@jonathanpeppers jonathanpeppers force-pushed the generatejavastubs-targetframework branch from 8dadab6 to 56da8ba Compare January 23, 2019 15:17
@jonpryor jonpryor merged commit 998fe61 into dotnet:master Jan 24, 2019
@jonathanpeppers jonathanpeppers deleted the generatejavastubs-targetframework branch April 5, 2019 19:01
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 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.

4 participants