We are developing a cross platform app on a PCL, but for the time being we are only using android devices for testing.
Our concern is that its taking about 6 to 8 seconds (depending on which device we test it) to start the app, which is very slow.
After placing a few breakpoints we saw that the timing is consumed pretty evenly.
We did notice this particular parts took longer:
- 1s before reaching onCreate() on MainActivity (there's a splash screen before which only has one image and a background color)
- 1s on
base.OnCreate(bundle);
- 1s on
global::Xamarin.Forms.Forms.Init(this, bundle);
- 1.5s on
Page mainPage = new LogScreen();
(creating the main page to then set it as main navigation page).
I'll put together all the solutions we found for this, so its all in one place.
One of the answers linked this post, which was very useful.
Besides that we also did the following things:
global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental");
onMainActivity.OnCreate()
method, beforeglobal::Xamarin.Forms.Forms.Init(this, bundle);
First thing I would recommend is to not benchmark a debug build of your app, the code paths of the Mono runtime and Jit'd code are not the same as a release build, the use of shared runtimes, assembly sizes, etc, etc, etc. will all effect the startup and execution times.
Here are examples of startup times of a "very large" aggressively tuned Android Forms-based app on high-end and low-end devices using an in-house benchmarker (conditionally compiled in, not injected, and using the OS's system clock).
App Overview:
MainActivity
will add:Times are generated via a shell script that reboots the devices, monitors the startup to wait for the system to settle, launches a series of apps (GApps, Facebook, Instagram, Twitter, etc...), waits for the system to settle, and then launches the Forms app via:
Google Pixel (Oreo-based) device (app is usable in ~430ms):
Low-end "Android One" 512MB device w/ very slow flash (app is usable in ~4.5s):
Re: https://en.wikipedia.org/wiki/Android_One
This is a common problem while using Xamarin.Forms there are many threads related to this specially this one:
https://forums.xamarin.com/discussion/93178/lets-talk-performance/p6
The good news is that the Xamarin team is working on it.
Here are some tips you can do improve it:
https://blog.xamarin.com/5-ways-boost-xamarin-forms-app-startup-time/