Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Install should skip Build when inside t…
Browse files Browse the repository at this point in the history
…he IDE

Context: https://github.com/xamarin/xamarin-android/wiki/IDE-Performance-Results
Context: https://github.com/jonathanpeppers/HelloWorld

When doing some performance measurements *inside* of Visual Studio, I
noticed we seem to have significant overhead in a build with no
changes.

In a "Hello World" Xamarin.Forms app:

    Preparation Time: 00:03.9
    Launch Time:      00:02.5

Where `Preparation Time` is everything MSBuild, and `Launch Time` is
the time it takes to start the Android application and attach the
debugger.

`Preparation Time` is effectively:

    msbuild Foo.Android.csproj /p:BuildingInsideVisualStudio=True /t:Build
    msbuild Foo.Android.csproj /p:BuildingInsideVisualStudio=True /t:Install

One concern here is that `Install` depends on `SignAndroidPackage`,
which depends on `Build`. We are doing a lot of MSBuild work here
twice, since MSBuild needs to run through certain targets twice and
decide they can be skipped. This work is "not free" and mostly
involved MSBuild evaluating properties and time stamps on files.

What I found we could do here is skip `Build` on the `Install` target
when `$(BuildingInsideVisualStudio)` is `True`. Due to the dependency
chain, this also affects `SignAndroidPackage`.

The minimal list of targets for `SignAndroidPackage` that still work:

- `_CreatePropertiesCache`
- `ResolveReferences`
- `_CopyPackage`
- `_Sign`

Initial results from the IDE show:

    Preparation Time: 00:02.06s

This is a ~2 second saving on the inner dev loop!

~~ Concerns ~~

Since our MSBuild tests set `$(BuildingInsideVisualStudio)`, a lot of
our tests might break. We might have to add an additional call to
`Build` in each failing test.
  • Loading branch information
jonathanpeppers committed Jan 18, 2019
1 parent 0d8942f commit 96e8e32
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,21 @@ because xbuild doesn't support framework reference assemblies.
<Delete Files="%(ApkAbiFilesUnaligned.FullPath)" />
</Target>

<Target Name="SignAndroidPackage" DependsOnTargets="Build;Package;_Sign">
<PropertyGroup>
<SignAndroidPackageDependsOn Condition=" '$(BuildingInsideVisualStudio)' != 'True' ">
Build;
Package;
_Sign;
</SignAndroidPackageDependsOn>
<!-- When inside an IDE, Build has just been run. This is a minimal list of targets for SignAndroidPackage. -->
<SignAndroidPackageDependsOn Condition=" '$(BuildingInsideVisualStudio)' == 'True' ">
_CreatePropertiesCache;
ResolveReferences;
_CopyPackage;
_Sign;
</SignAndroidPackageDependsOn>
</PropertyGroup>
<Target Name="SignAndroidPackage" DependsOnTargets="$(SignAndroidPackageDependsOn)">
</Target>

<PropertyGroup>
Expand Down

0 comments on commit 96e8e32

Please sign in to comment.