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

Blank Xamarin.Forms App Template in 2019 builds slower #2982

Open
jonathanpeppers opened this Issue Apr 15, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@jonathanpeppers
Copy link
Member

jonathanpeppers commented Apr 15, 2019

Steps to Reproduce

  1. Create a blank Xamarin.Forms app in 2019, build
  2. Do the same in 2017

In comparison, the notable difference I see (when using d8): _CompileDex goes from ~15.2s to ~18.2 seconds. The bulk of the build time here is javac + dexing.

If I compare the d8 calls:

image

There are 20 more jar files!!!

And if you look at a diff, I think it is merely the set of <PackageReference/> causing it:

<ItemGroup>
-    <PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
-    <PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2.1" />
-    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2.1" />
-    <PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2.1" />
-    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="27.0.2.1" />
-    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="27.0.2.1" />
+    <PackageReference Include="Xamarin.Forms" Version="3.6.0.264807" />
+    <PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
+    <PackageReference Include="Xamarin.Essentials" Version="1.0.1" />
   </ItemGroup>

See this project here.

Expected Behavior

New project templates in 2019 have comparable build times to 2017. It's OK to be a little slower when adding a few libraries.

Actual Behavior

For some reason the default template has 20 more jar files? I feel like there is something to investigate here.

@jonathanpeppers

This comment has been minimized.

Copy link
Member Author

jonathanpeppers commented Apr 15, 2019

Here is a diff of the assemblies: https://www.diffchecker.com/swvGOfCw

Difference in dex size:

classes.dex 3525256 -> 4048548

jonathanpeppers added a commit to jonathanpeppers/Xamarin.Forms that referenced this issue Apr 17, 2019

Remove Xamarin.Android.Support.v7.MediaRouter
Context: xamarin/xamarin-android#2982

The Blank Xamarin.Forms app template in VS 2019 takes longer to build
than in VS 2017. A little research is showing that this is due to use
of the 28.x support libraries... For example, the build includes ~20
*more* jar files in the template from 2019 than 2017. The
`_CompileDex` step alone goes from ~15.2s to ~18.2s.

This lead me down the road of investigating if we can remove any
support libraries by default in Xamarin.Forms apps. I am also seeing
if there is more we can do in Xamarin.Android for this problem, in
general.

It looks like we can remove:

* Xamarin.Android.Support.v7.MediaRouter
* Xamarin.Android.Support.Media.Compat

Neither of these appear to be used, but have been listed as
dependencies of Xamarin.Forms for a long time.

~~ Results ~~

I made these changes, then did a `Debug` build of
`Xamarin.Forms.ControlGallery.Android.csproj` for comparison.

Comparing dex file sizes (in bytes):

    Before:
    3428092 classes.dex
    3265616 classes2.dex
    6693708 total
    After:
    4938000 classes.dex
    1098772 classes2.dex
    6036772 total

This looks like it could potentially save ~600KB of compiled dex code
on every Xamarin.Forms app.

Comparing methods:

    Before:
    classes.dex  11,492 methods
    classes2.dex 19,451 methods
    total        30,943 methods
    After:
    classes.dex  22,171 methods
    classes2.dex  7,635 methods
    total        29,806 methods

~1,137 methods removed, which should help with the dex limit.

Comparing APK sizes (in bytes):

    Before:
    26442597 AndroidControlGallery.AndroidControlGallery-Signed.apk
    After:
    25741701 AndroidControlGallery.AndroidControlGallery-Signed.apk

~700KB smaller APK, due to less .NET assemblies & dex code.

Comparing build time (this was using dx):

    Before:
    19785 ms  CompileToDalvik                            1 calls
    After:
    18532 ms  CompileToDalvik                            1 calls

Looks like it saved over a second of build time for this project.

Seems like an "easy win", let's do this!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.