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
I would first have you check the actual difference between a Debug
configuration vs. a signed Release
configuration in terms of "Startup Performance".
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.
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.
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.
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.
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:
OnCreate()
.apk
as much as you possibly can for a fast load time