7

My Android app (created using Xamarin.Forms) takes around 10 seconds to start (both in Debug & Release mode) on a real device (Asus Zenfone 2). The splash screen is showing for 8 seconds. Here is my log attached where as "extrony" is my app name. Only assembly loading takes this much time. Any help?

Android Startup log

EDIT 1: It actually takes 10 seconds (I mentioned 8 by mistake, but updated now)

EDIT 2: On an Emulator (I am using Android Emulator for Visual Studio) the app starts faster i.e. within 4.3seconds. However on my real device (Asus Zenfone2), the time it takes is 10seconds. Here is additional thing I see on the debug output while debugging on a real device (It doesn't appear if you debug on the emulator) and loading these assemblies ALONE takes ~6seconds.

Android application is debugging.
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/extrony.Droid.dll
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Acr.Support.Android.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Acr.UserDialogs.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Acr.UserDialogs.Interface.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/AndHUD.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/CarouselView.FormsPlugin.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/CarouselView.FormsPlugin.Android.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.Forms.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.Forms.Droid.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.Platform.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FormsViewGroup.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/HtmlAgilityPack.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Analytics.Android.Bindings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Analytics.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Android.Bindings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Crashes.Android.Bindings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Crashes.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Data.Sqlite.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.EntityFrameworkCore.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.EntityFrameworkCore.Relational.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.EntityFrameworkCore.Sqlite.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Caching.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Caching.Memory.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.DependencyInjection.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.DependencyInjection.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Logging.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Logging.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Options.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Primitives.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/ModernHttpClient.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Newtonsoft.Json.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/OkHttp.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Connectivity.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Connectivity.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.CurrentActivity.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Settings.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Settings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Share.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Share.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Remotion.Linq.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/SgmlReaderDll.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Splat.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Collections.Immutable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Diagnostics.DiagnosticSource.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Interactive.Async.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Runtime.CompilerServices.Unsafe.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.Animated.Vector.Drawable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.CustomTabs.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.Design.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v4.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.AppCompat.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.CardView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.MediaRouter.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.RecyclerView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.Vector.Drawable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Core.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Platform.Android.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/extrony.dll
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/extrony.Data.dll
Loaded assembly: Mono.Android.dll [External]
Loaded assembly: Java.Interop.dll [External]
Loaded assembly: System.Runtime.dll [External]
Loaded assembly: System.Collections.Concurrent.dll [External]
Loaded assembly: System.Reflection.dll [External]
Loaded assembly: System.Threading.dll [External]
Loaded assembly: System.Diagnostics.Debug.dll [External]
Loaded assembly: System.dll [External]
Loaded assembly: System.Runtime.InteropServices.dll [External]
Loaded assembly: System.Collections.dll [External]
Loaded assembly: System.Linq.dll [External]
Loaded assembly: System.Core.dll [External]
Loaded assembly: System.Reflection.Extensions.dll [External]
Loaded assembly: MonoDroidConstructors [External]
Loaded assembly: System.ObjectModel.dll [External]
Loaded assembly: System.Threading.Tasks.dll [External]
Loaded assembly: System.Xml.ReaderWriter.dll [External]
Loaded assembly: System.Xml.dll [External]
Loaded assembly: System.IO.dll [External]
Loaded assembly: System.Runtime.Extensions.dll [External]
Loaded assembly: System.Linq.Expressions.dll [External]
Loaded assembly: System.Resources.ResourceManager.dll [External]
Loaded assembly: System.Globalization.dll [External]
Loaded assembly: System.Dynamic.Runtime.dll [External]
Loaded assembly: System.ComponentModel.dll [External]
Thread started: <Thread Pool> #2
Thread started: <Thread Pool> #3
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
Loaded assembly: System.Linq.Queryable.dll [External]
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
Loaded assembly: System.Data.Common.dll [External]
Loaded assembly: System.Data.dll [External]
Thread started: <Thread Pool> #6
Loaded assembly: System.Diagnostics.Tracing.dll [External]
Loaded assembly: System.ComponentModel.Annotations.dll [External]
Loaded assembly: System.ComponentModel.DataAnnotations.dll [External]

EDIT 3: Tested on different devices per suggestion received via comments. These are the results (from a release build)

  • ~8 to 10 seconds on Samsung Galaxy OnNXT
  • ~6-7 seconds on Xiaomi Mi Max Prime
  • ~4-5 seconds on Redmi Note 3
  • ~9.5 seconds on Asus Zenfone2

Edit 4: I have done a very detailed testing and I can confirm that "context.Migrate() and a simple query with SingleOrDefault()" (EFCore) takes 9 seconds. If I remove this call, the app starts in ~3 seconds.

EDIT 5: I was expecting to do the db init on a different thread in the splash activity (like the below), since the Xamarin.Forms initialization (usually) takes around 3 seconds and I want the init also to happen in parallel. However it appears that even though it runs on a different thread the EFCore db init also contributes to the start-up time. Am I doing anything wrong?

 protected override void OnResume()
    {
        base.OnResume();

        System.Threading.Tasks.Task.Run(() =>
        {
            App.DbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            App.InitializeDb();
        });

        StartActivity(typeof(MainActivity));

    }

Any help with a suggestion?

8
  • Are you running on emulator or on real device? Commented Apr 1, 2017 at 2:58
  • Not sure, why this question is down voted. Please let me know and I can remove if it is really a bad question. Commented Apr 1, 2017 at 3:42
  • You might try sharing the startup code as part of the question. You might also try commenting out certain startup steps to see if the time is reduced, and include those findings too. This way the question meets the tests of shows code and attempt to self-solve. Meanwhile, 8 seconds seems pretty normal to start the app in debug mode and have the debugger attach, but would be quite long for a release build launched from the device apps page. Commented Apr 1, 2017 at 4:10
  • Okay. I actually attached the log and thought the log gives full info. Apart from using those libraries I don't have any other expensive operations happening on the first page. Thought the log I gave for debug mode, a release build running on a mobile takes 8 seconds too. If it's not normal I will try re-creating this in a sample app. Commented Apr 1, 2017 at 7:00
  • What version of Forms? The latest pre-release has some startup time improvements. Commented Apr 1, 2017 at 7:17

2 Answers 2

4

4.5 Seconds is being taken up by this section, if this is an accurate representation of when the app finishes loading.

04-01 07:53:15.443 D/Mono    ( 1742): [0x9ac5e930] hill climbing, change max number of threads 2
04-01 07:53:15.445 W/art     ( 1742): JNI RegisterNativeMethods: attempt to register 0 native methods for md54ada4fbe4a5955f6151fa282d30cfc48.SelfDisposingBitmapDrawable
Resolved pending breakpoint at 'CleanUpReceiver.cs:16,1' to void extrony.Droid.Receivers.CleanUpReceiver.OnReceive (Android.Content.Context context, Android.Content.Intent intent) [0x00000].
04-01 07:53:20.059 D/Mono    ( 1742): DllImport searching in: '/system/lib/libsqlite.so' ('/system/lib/libsqlite.so').
04-01 07:53:20.059 D/Mono    ( 1742): Searching for 'sqlite3_column_count'.

Everything is loaded at this point, hence it's something in your code, most likely in the App.xaml.cs constructor. I notice you also have EF Core as well.

There could be many things going on here, but until App.xaml.cs is completed, it will still show the splashscreen.

I would recommend adding a StopWatch in parts of your code on startup and see what is taking the time. From there you could ask a different question in stackoverflow relating that problem.

System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
s.Start();

// Code in here

s.Stop();
System.Diagnostics.Debug.WriteLine($"Elapsed Time: {s.ElapsedMilliseconds.ToString("N0")}");
Sign up to request clarification or add additional context in comments.

23 Comments

Great direction. Thank you! I will try that and come back with my findings.
Just FYI. It actually takes 10 seconds. Not sure, why I typed 8. I tested again multiple times. Updated my question as well. Trying with what Adam advised with.
Thank you Adam. While testing observed one more thing. Please see my EDIT2. Any clue?
I noticed you mentioned you loaded ProGuard. Does the startup time improve if you uncheck proguard. You can also test if you uncheck or check shared runtime.
Switching ProGuard or Shared runtime On or Off doesn't seem to have any impact. Also the timing is same in both Debug & Release. This takes too long only on the real device but the emulator looks to be faster (see EDIT2 in my question). Any idea what are those "Loaded Assembly ...." messages I get only on the device?
|
-1

If your Main Page calls services , loads data or does something that needs some time to complete, you can add splash screen . This is solve my problem on android.

http://www.c-sharpcorner.com/UploadFile/oussamaalrifai/xamarin-forms-android-workaround-for-splash-screen-with-lo/

1 Comment

I did that already as you can see in my question. Thanks for the link though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.