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 app starts up slower when built using VS2019 #3366

Closed
bellissimo opened this issue Jul 18, 2019 · 8 comments
Closed

Xamarin.Android app starts up slower when built using VS2019 #3366

bellissimo opened this issue Jul 18, 2019 · 8 comments
Assignees

Comments

@bellissimo
Copy link

bellissimo commented Jul 18, 2019

I am currently using VS2017, but when I tried my app using VS2019 I noticed that the startup time was significantly slower (ca. 20% slower). I measured the startup times on real devices by checking the 'Displayed' logging line that Android provides to show that the main activity is shown.

This scenario is when 'AOT' is turned on (I also turned on LLVM, but this had little effect on timings whether it was on or off).

I thought I would try out a template Xamarin.Android app to rule out any app specific issue, so I created the 'Tabbed' app template (so that it would have a reasonable number of libs). I then tested startup times (averaging across 10 startups) on two devices. Each time I switched between VS2017 and VS2019 I did a 'Clean' and also deleted the 'obj' folder for good measure.

Any comments or suggestions to progress this further would be welcome. Given that Google are tending to punish slow starting apps more severely in the rankings, this is currently stopping me upgrading to VS2019.

Below were my startup timings:

Samsung Galaxy S7

VS2017 - 420ms
VS2019 - 470ms

Samsung Galaxy S9

VS2017 - 380ms
VS2019 - 440ms

Steps to Reproduce

  1. Create new 'Tabbed' template project
  2. Additionally set the following in the csproj file:
    <AotAssemblies>true</AotAssemblies>
    <EnableLLVM>true</EnableLLVM>
    <AndroidEnablePreloadAssemblies>true</AndroidEnablePreloadAssemblies>
  3. Build and Run app in Release mode using VS2017 and check the 'Displayed' timings in the log
  4. Build and Run app in Release mode using VS2019 and check the 'Displayed' timings in the log

Expected Behavior

Given the improvements made to startup times in VS2019, the startup time should be quicker in VS2019, or at least equivalent to VS2017.

Actual Behavior

Startup time is approx. 10-20% slower when built using VS2019

Version Information

VS2019

Microsoft Visual Studio Professional 2019
Version 16.1.6
VisualStudio.16.Release/16.1.6+29102.190
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Professional

Azure App Service Tools v3.0.0 16.1.429.50124
Azure App Service Tools v3.0.0

C# Tools 3.1.1-beta4-19281-06+58a4b1e79aea28115e66b06f850c83a3f1fcb6d3
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.1.77 (master@24013d5)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Mono Debugging for Visual Studio 16.1.1 (2473f22)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 5.1.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

Visual Basic Tools 3.1.1-beta4-19281-06+58a4b1e79aea28115e66b06f850c83a3f1fcb6d3
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6 16.1.0-beta.19253.3+42526fe359672a05fd562dc16a91a43d0fe047a7
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Xamarin 16.1.0.545 (d16-1@db7c858e8)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 16.1.0.418 (remotes/origin/d16-1@5b958bb10)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 16.2.112 (4db4af4)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.3.0.23 (HEAD/d0b48056f)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: mono/mono@3a07bd426d3
Java.Interop: xamarin/java.interop/d16-1@5ddc3e3
LibZipSharp: grendello/LibZipSharp/d16-1@44de300
LibZip: nih-at/libzip@b95cf3f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-1@acabd26

Xamarin.iOS and Xamarin.Mac SDK 12.10.0.157 (6bd9475)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

VS2017

Microsoft Visual Studio Professional 2017
Version 15.9.8
VisualStudio.15.Release/15.9.8+28307.481
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Professional

Visual C++ 2017 00369-60000-00001-AA801
Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.14.20131.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.9.04012.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590
Provides languages services for ASP.NET Core Razor.

Azure App Service Tools v3.0.0 15.9.03024.0
Azure App Service Tools v3.0.0

C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service 2.0
JavaScript Language Service

JavaScript Project System 2.0
JavaScript Project System

JavaScript UWP Project System 2.0
JavaScript UWP Project System

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

MLGen Package Extension 1.0
MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.13.12-pre (9bc9548)
Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.4.21001.1 Commit Hash:8dd15923800d931b153ab9e4de74e42a74eba5e6
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61902.21100
Microsoft SQL Server Data Tools

TypeScript Tools 15.9.20918.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers 1.0
Visual Studio Tools for Containers

Visual Studio Tools for Universal Windows Apps 15.0.28307.421
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Xamarin 4.12.3.80 (d15-9@914127c74)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.16.13 (45a16efd4)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.128 (6f5ebb2)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.1.7.0 (HEAD/ba9da7a76)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.2.1.15 (d60abd1)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

@radekdoulik
Copy link
Member

Try to set AndroidEnablePreloadAssemblies to false. That should help with the startup performance a bit.

@radekdoulik
Copy link
Member

Also try VS 16.2 previews if possible. We did some performance improvements in 16.2.

@bellissimo
Copy link
Author

bellissimo commented Jul 19, 2019

Thanks for responding. I have used those two suggestions and made some new timings. I also did equivalent timings with AOT turned off, which makes an interesting comparison.

The takeout for AOT is that by not pre-loading the assemblies you save a few milliseconds and by using VS 2019 16.2 Preview you save a few milliseconds more and bring the results pretty much back in line with VS 2017.

With AOT turned off, the time savings are fairly significant just by moving to VS 2019, with more time savings gained by not pre-loading assemblies and using 16.2 Preview (similar to the incremental savings with AOT turned on).

Do we know why having AOT turned on means there are no time gains compared to having it turned off?

AOT On

Samsung Galaxy S7

VS2017 420ms
VS2019 470ms (Pre-loaded assemblies)
VS2019 420ms (Not pre-loaded)
VS2019 Preview 410ms (Not pre-loaded)

Samsung Galaxy S9

VS2017 380ms
VS2019 440ms (Pre-loaded assemblies)
VS2019 410ms (Not pre-loaded)
VS2019 Preview 390ms (Not pre-loaded)

AOT Off

Samsung Galaxy S7

VS2017 730ms
VS2019 650ms (Pre-loaded assemblies)
VS2019 630ms (Not pre-loaded)
VS2019 Preview 605ms (Not pre-loaded)

Samsung Galaxy S9

VS2017 630ms
VS2019 550ms (Pre-loaded assemblies)
VS2019 530ms (Not pre-loaded)
VS2019 Preview 505ms (Not pre-loaded)

@grendello
Copy link
Contributor

@bellissimo AOT might be slower because of the generated .so size and because the binary might not be position-independent code and the need to apply relocations while loading a large binary might take a long time. @radekdoulik can we check if AOT binaries built with VS2019 are PIC or not?

@radekdoulik
Copy link
Member

Looks like they contain text relocations:

arm-linux-androideabi-readelf --dynamic tests/Xamarin.Forms-Performance-Integration/Droid/obj/Debug/aot/armeabi-v7a/libaot-mscorlib.dll.so|grep TEXT
 0x00000016 (TEXTREL)                    0x0
 0x0000001e (FLAGS)                      TEXTREL

We should probably change that in future. It might gain us few more ms.

@grendello grendello removed their assignment Aug 20, 2019
@RadoslawKubas
Copy link

RadoslawKubas commented Aug 22, 2019

I noticed similar problem, when I build Xamarin.Forms Android platform release using App Center, the startup time with SDK Xamarin.Android 9.4 (Mono 6.0) is much worst than Xamarin.Android 9.3 (Mono 5.18). I did some tests today with AOT enabled and disabled, and data looks strange. It seems that with 9.4 startup time with AOT and without AOT is almost same and about 100% more than 9.3 AOT version.

startup_time_2

jonpryor added a commit that referenced this issue Sep 4, 2019
jonpryor added a commit that referenced this issue Sep 5, 2019
@pjcollins
Copy link
Member

I followed similar test steps as mentioned above to test this across a few XA releases and old/budget devices:

  1. Create a new Xamarin.Forms Tabbed App template with VS2019 16.2.
  2. Installed it on various devices with and without AOT enabled.
  3. Recorded the elapsed time between ActivityManager: Start proc and ActivityManager: Displayed messages for a "cold" launch attempt.

Results

image

*The asterisk on the d16-4 AOT results indicate that this .apk was built on macOS. All other cases were built and deployed on Windows, however #3619 is currently blocking AOT usage on Windows in recent builds.

jonpryor pushed a commit that referenced this issue Sep 13, 2019
Changes: mono/mono@29b1ac1...cecda47

Context: mono/mono#16486
Context: #3366

Bumps to mono/corefx@e79cf5b.

Adds `aprofutil.exe`, a utility for parsing `.aotprofile` files.
See also a3fb59a.  (`aotprofile-tool` was renamed to `aprofutil`).

Introduces a different fix to prevent .text relocations in AOT output
while removing the previous implicit assembly size limit.
jonpryor pushed a commit that referenced this issue Sep 20, 2019
Changes: mono/mono@29b1ac1...cecda47

Context: mono/mono#16486
Context: #3366

Bumps to mono/corefx@e79cf5b.

Adds `aprofutil.exe`, a utility for parsing `.aotprofile` files.
See also a3fb59a.  (`aotprofile-tool` was renamed to `aprofutil`).

Introduces a different fix to prevent .text relocations in AOT output
while removing the previous implicit assembly size limit.
@jpobst
Copy link
Contributor

jpobst commented Aug 8, 2022

This is likely much better nowadays with the extensive performance work we've done over the past 2 years:
https://devblogs.microsoft.com/dotnet/performance-improvements-in-dotnet-maui/

Even though it says MAUI, many changes were made in XA which will improve all XA app performance.

@jpobst jpobst closed this as completed Aug 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants