4

How can I improve startup performance/lower startup time (time that is used between app is tapped and the intro screen appears) on my android app that is written in C# using Xamarin.Android approach.

Since my device is not the oldest (Motorola Moto G3) I wonder why some big commercial apps/games such as Clash of Clans and Facebook have so little "blackscreen" time and my little-bittle easy-cheesy android app that does not even load data from the local storage (just creating a datamodel from hard coded values) takes so long to show the intro screen.

Even when creating a complete new app and starting this on my phone via adb there is some delay Thanks in advance

Radinator
  • 1,048
  • 18
  • 58

1 Answers1

1

I would first have you check the actual difference between a Debug configuration vs. a signed Release configuration in terms of "Startup Performance".

https://developer.xamarin.com/guides/android/advanced_topics/application_package_sizes/#Release_Packages

Sadly a Debug configuration has a bit of items that are required to be in place in order to debug. This is also known as the Shared Runtime and Shared Platform. This is ~10MB to copy over on first run.

https://developer.xamarin.com/guides/android/advanced_topics/application_package_sizes/#Debug_Packages

Copying these core components is only done once as it takes quite a bit of time, but allows any subsequent applications running in debug mode to utilize them. Finally, we copy the actual application, which is small and quick:

So that might be one factor. But let's talk about some of the other options while we're here:

You can also use Fast Assembly Deployment which will install the assemblies directly on the device only once and then it will copy files that have been modified since the previous deployment.

https://developer.xamarin.com/guides/android/advanced_topics/application_package_sizes/#Fast_Assembly_Deployment

Note: These two settings are "on" by default via the following MSBuild Properties: <AndroidUseSharedRuntime>true</AndroidUseSharedRuntime> and <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>

Next you can use AOT(Note: Is experimental at the time of writing):

The AOT Compilation option (on the Packaging Properties page) enables Ahead-of-Time (AOT) compilation of assemblies. When this option is enabled, Just In Time (JIT) startup overhead is minimized by precompiling assemblies before runtime. The resulting native code is included in the APK along with the uncompiled assemblies. This results in shorter application startup time, but at the expense of slightly larger APK sizes.

The AOT Compilation option requires an Enterprise license or higher. AOT compilation is available only when the project is configured for Release mode, and it is disabled by default. For more information about AOT Compilation, see AOT.

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/#AOT_Compilation

Finally you can enable the LLVM Optimization Compiler(Note: Is experimental at the time of writing):

When the AOT Compilation option is enabled (on the Packaging Properties page), you can choose to enable the LLVM Optimizing Compiler for converting AOT-compiled assemblies into native code. The LLVM compiler creates smaller and faster compiled code, but at the expense of slower build times. The LLVM compiler is disabled by default.

Note that the LLVM Optimizing Compiler option requires a Business license or higher and is available only when AOT Compilation is enabled.

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/#LLVM_Optimizing_Compiler

Please keep this note in mind when using both AOT and LLVM:

NOTE: AOT is currently an experimental feature. It is not recommended for production use. AOT and LLVM was available in Xamarin.Android 5.1, but it is no longer available in later Xamarin.Android versions. For more information, please see the release notes.

Other items that can be related, but I won't go into detail based on your "File -> New Project" assumptions:

  • Doing too much work before the application exits OnCreate()
  • Not shrinking your .apk as much as you possibly can for a fast load time
Community
  • 1
  • 1
Jon Douglas
  • 13,006
  • 4
  • 38
  • 51
  • Added a note based on the link I already had in the [AOT Documentation](https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/#AOT_Compilation): – Jon Douglas Nov 08 '16 at 17:50
  • Sorry, missed that, not enough coffee yet :-) – SushiHangover Nov 08 '16 at 17:54
  • AOT have been removed since Xamarin 6.1([release note](https://developer.xamarin.com/releases/android/xamarin.android_6/xamarin.android_6.1)) I will keep my slow starting app :s – Drakkin Mar 21 '17 at 16:59
  • That is AOT+LLVM only. – Jon Douglas Mar 21 '17 at 18:13