Forum Xamarin Xamarin.Forms

Xamarin Forms startup times are unusably slow

BlueRajaBlueRaja USMember ✭✭
edited September 2016 in Xamarin.Forms

My startup screen shows two buttons and a label in a StackLayout, and does nothing more. I've timed the app to take 2.5~3.0 seconds just to show that screen, in Release mode, on an actual device (Motorola Mini XT1030). That's an absurd and unacceptable amount of time to show nothing to the user. As far as I can tell, there's no way to show a splash-screen during that initial loading.

Yes, I'm using [assembly: XamlCompilation(XamlCompilationOptions.Compile)] (without it startup times are around 4.2s!). Running Xamarin Profiler, I see that 100% of the startup code is out of my control.

Is there anything else I can do to speed up my startup times? Or is Xamarin Forms really still not production-ready, and I should start recreating all my UIs on every platform?

Answers

  • BlueRajaBlueRaja USMember ✭✭
    edited September 2016

    Forgot to mention: I'm running Xamarin Forms 2.3.1.114

    I tried to test AOT/LLVM to see if they improve startup time, but unfortunately they don't seem to actually work.

    Edit After a bit more research, it seems it is possible to show a loading screen (additional link). However, that still does not excuse the horrendous startup times. This needs to be addressed.

  • AlxDiAlxDi USMember

    Same problem here.
    I have tested a similar program (StackLayout, 1xLabel, 1xButton) on iPhone4 and Samsung S3.
    I also used XAMLC and release versions to meassure startup.

    My results:
    iPhone4:

    • Native program (same structure) in swift: <1s -the app was immediately loaded.
    • Xamarin.iOS program: ~2s
    • Xamarin.Forms: ~3s

    Samsung S3:

    • Xamarin.Android program: ~2s
    • Xamarin.Forms: ~3s

    If we make things bigger, say using a Grid containing 100 Buttons, the startup time rises to over 10 seconds.
    I would be interested to know if there is a way to speed things up.

  • BlueRajaBlueRaja USMember ✭✭
    edited September 2016
  • BlueRajaBlueRaja USMember ✭✭
    edited September 2016

    Bump. Does anyone know if anyone from Xamarin checks these forums?

  • My results:
    iPhone4:

    • Native program (same structure) in swift: <1s -the app was immediately loaded.
    • Xamarin.iOS program: ~2s
    • Xamarin.Forms: ~3s

    Samsung S3:

    • Xamarin.Android program: ~2s
    • Xamarin.Forms: ~3s

    If we make things bigger, say using a Grid containing 100 Buttons, the startup time rises to over 10 seconds.
    I would be interested to know if there is a way to speed things up.

    I see a big difference in app startup times on iOS and Android:
    iPhone 4s:

    • Native program: instant start
    • Xamarin Forms: 3.5s

    Samsung S4:

    • Xamarin Forms: 7.5s.

    This is a fairly large app with a moderately complex screen (some nested layouts), though not with a lot of elements and no images on the initial screen. But most of the startup time seems to be taken up by loading all manner of DLLs.

  • JohnHardmanJohnHardman GBUniversity admin

    Having started looking at some of the source for Xamarin.Forms, I think some bits that could be contributing to slow startup times would be likely to require breaking changes to overcome. I haven't checked in detail yet, but that's my suspicion based on what I have looked at so far. It would be good if a Xamarin insider could give some indication as to what work is being done to improve startup performance, as well as providing any guidance on how we can tweak our code to do what we can in this respect too.

  • JohnHJohnH GBMember ✭✭✭✭✭

    My apps are hybrid Xamarin.iOS native to forms, my app startup (in release config) is less than a second, but the first time I open a XF page I see a one off delay. Not sure if that info will be helpful to anyone though.

  • ChrisColeTechChrisColeTech USMember ✭✭✭

    @BlueRaja said:
    Bump. Does anyone know if anyone from Xamarin checks these forums?

    yes, but they'll more than likely just tell you to contact support or go file a bug report :/

  • JulienRosenJulienRosen CAMember ✭✭✭✭
    edited September 2016

    [deleted]

  • luigitniluigitni ITMember ✭✭

    2.5s - 3s would be glorious.
    I am showing a grouped listview with data taken from a database and it takes around 8 seconds on a Samsung Galaxy S4 and ~ 5 on a Nexus 5 (on a cold start).
    Logging the time it takes to execute my start up code in OnCreate shows around 800ms, including the call to LaunchApp.
    It seems that the largest amount of start-up time is being taken by the loading of dlls and OpenGL(?):

    [Mono] DllImport searching in: '__Internal' ('(null)').
    [Mono] Searching for 'java_interop_jnienv_new_local_ref'.
    [Mono] Probing 'java_interop_jnienv_new_local_ref'.
    [Mono] Found as 'java_interop_jnienv_new_local_ref'.
    [Adreno-EGL] <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    [Adreno-EGL] OpenGL ES Shader Compiler Version: E031.25.03.06
    [Adreno-EGL] Build Date: 01/24/15 Sat
    [Adreno-EGL] Local Branch: AF11_RB1_AU15
    [Adreno-EGL] Remote Branch: 
    [Adreno-EGL] Local Patches: 
    [Adreno-EGL] Reconstruct Branch: 
    [OpenGLRenderer] Initialized EGL, version 1.4
    [OpenGLRenderer] Enabling debug mode 0
    [Mono] [0x9af80300] hill climbing, change max number of threads 4
    [Mono] DllImport searching in: '__Internal' ('(null)').
    [Mono] Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'.
    [Mono] Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'.
    [Mono] Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'.
    [Mono] Unloading image System.Collections.dll [0x9aeead00].
    [Mono] Image addref System.Collections[0x9b5f7f40] -> System.Collections.dll[0xb4d27000]: 9
    [Mono] Config attempting to parse: 'System.Collections.dll.config'.
    [Mono] Config attempting to parse: '/Users/builder/data/lanes/3511/f4db8a57/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/System.Collections/System.Collections.config'.
    [Mono] Assembly Ref addref MvvmHelpers[0xb3945760] -> System.Collections[0xb0ce4fa0]: 7
    [Mono] [0x9b2b8580] hill climbing, change max number of threads 24
    [Mono] [0x9af80300] hill climbing, change max number of threads 42
    [art] JNI RegisterNativeMethods: attempt to register 0 native methods for md5b60ffeb829f638581ab2bb9b1a7f4f3f.Platform_DefaultRenderer
    [Mono] [0x9af80300] hill climbing, change max number of threads 34
    [AbsListView] Get MotionRecognitionManager
    [Mono] [0x9af80300] hill climbing, change max number of threads 16
    [art] JNI RegisterNativeMethods: attempt to register 0 native methods for md5b60ffeb829f638581ab2bb9b1a7f4f3f.LabelRenderer
    [Mono] [0x9af80300] hill climbing, change max number of threads 30
    [Mono] [0xb4df8d80] hill climbing, change max number of threads 24
    

    Useless to say, we and our contractor are not happy at all with this behaviour, which is costing our company development time and frustration and which, in our regards, should have been better advertized on the home page.

    We still believe that XF could be a great compromise to accomodate low-budget multi platform apps, but as it stays now it moves all the development costs towards developers which need to accomodate code to overcome the platform bugs.
    It is indeed one of the most frustrating development experience I ever had in years of native iOS and Android development, which is a pity given its potential.

    Enough with the rant, I have not been able to find any official documentation/Q&A/forum post regarding possible common pitfalls, optimization tips for linkers settings etc. Am I wrong? Is there a somehow in-depth article that explains why the startup time is so high and what needs to be done to have acceptable performance if that's even possible?

  • MikeeSouthMikeeSouth USMember ✭✭

    Any official response here? I'm also very eager to know if there are optimizations available to reduce the startup time. I can agree with the frustrating development experience but lets keep this thread focused on the startup times.

    I'm seing ~3s startup time for a very simple XF app on Android (Samsung S7 Edge). This is a powerful phone so I would guess that an older phone has up to 6-7s startup time, unfortunately.

    Again - can we get an official response that explains why?

  • MikeeSouthMikeeSouth USMember ✭✭

    It seems like AOT "Mono Ahead-Of-Time compiler" can help quite a bit. I switched VS to release mode and then enabled both "AOT" and "LLVM Optimizing Compiler" in the Android Options tab in the Droid Project Properties. Compilation took much longer than in debug but startup time was greatly reduced. I estimated my app to about 1s instead of 3s and I'm using a splash so maybe it can be even less. I'm gonna experiment more with this sometime in the near future.

  • Thanks for the tip!
    From the logs above. Can anyone explain the following line can be translated?
    Assembly Ref addref MvvmHelpers[0xb3945760] -> System.Collections[0xb0ce4fa0]: 7
    Does it meant that MvvmHelpers is referencing System.Collections and therefore the corresponding assembly will be loaded?
    What does the digit 7 at the end stand for?

  • Shane000Shane000 USMember ✭✭✭

    "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 Xamarin.Android 6.1 release notes"

    https://developer.xamarin.com/guides/android/deployment,testing,_and_metrics/publishing_an_application/part_1-_preparing_an_application_for_release/

    I can't even find that in the current Xamarin Studio. Has anyone actually improved startup time? Our app's startup time on lower tier phones is unacceptable.

  • Shane000Shane000 USMember ✭✭✭

    I think I would like to delay load a specific library is that even possible?

  • batmacibatmaci DEMember ✭✭✭✭✭
    Any good solution here please
  • batmacibatmaci DEMember ✭✭✭✭✭

    I tried aot and really reduced from 10 secs to 5secs but my app was increased from 20mb to 56mb which is not acceptable for me. I am using already full linking, proguard and even bundle into native assemblies options.

  • ClayZuvichClayZuvich USMember ✭✭✭

    @batmaci Unfortunately, not much can be done about the file size. See https://xamarinhelp.com/reducing-app-file-size-xamarin-forms/

    I've experienced slowness when trying to load any data via reflection on the main thread during startup. I changed my routines to just plain JsonReader/Writer, and it improved significantly.

  • batmacibatmaci DEMember ✭✭✭✭✭
    > @ClayZuvich said:
    > @batmaci Unfortunately, not much can be done about the file size. See https://xamarinhelp.com/reducing-app-file-size-xamarin-forms/
    >
    > I've experienced slowness when trying to load any data via reflection on the main thread during startup. I changed my routines to just plain JsonReader/Writer, and it improved significantly.

    Do you mean that you dont use sqlite or any other DB but simply read from txt file using jsonreader /writer? Can you extend your solution?
  • batmacibatmaci DEMember ✭✭✭✭✭
    Is it actually not possible to Display a splashscreen page with animated Progress bar?
  • MulflarMulflar ESUniversity ✭✭

    @batmaci said:
    Is it actually not possible to Display a splashscreen page with animated Progress bar?

    I'ts posible if you do it like a "normal" view. I have some apps with "double" splash screen the static one who does nothing else than navigation, and then the second one who manages all the startup services with a progress bar.

  • batmacibatmaci DEMember ✭✭✭✭✭

    @Mulflar said:

    @batmaci said:
    Is it actually not possible to Display a splashscreen page with animated Progress bar?

    I'ts posible if you do it like a "normal" view. I have some apps with "double" splash screen the static one who does nothing else than navigation, and then the second one who manages all the startup services with a progress bar.

    You mean that you are using splash activity. I was using that as well and it always had a white screen problem before splash screen displayed. I decided without doing this solution.

  • MulflarMulflar ESUniversity ✭✭

    I have a splash activity in android who only shows a static image (as a style) and then moves to the main activity who "starts" the forms app, then I have a splash viewmodel who shows the same image plus a loading bar and in that viewmodel I chek the user is loged, download the settings, etc...

  • ClayZuvichClayZuvich USMember ✭✭

    @batmaci
    I still use SQLite. I've only developed one Forms application, and for that app I serialized objects to SQLite in a JSON blob with only a few columns for indexing/lookups (identifiers).

    I was using Newtonsoft reflection to load some of those objects from the database in the main thread on startup of the app; however, I switched to using JsonReader/Writer and performance improved significantly.

    I'm only loading a handful of objects, so I didn't bother with a Splash page with a loading screen.

  • any official solution yet?

  • JohnHJohnH GBMember ✭✭✭✭✭

    @ReihanehKhaksaran said:
    any official solution yet?

    There are many possible reasons for slow app startup time, so it all depends on what your app is doing. If you provide more detail, I'm sure someone will be able to give you pointers.

  • BlueRajaBlueRaja USMember ✭✭

    @JohnHair The issue is that the startup time on an absolute barebones Xamarin Forms project is unreasonably slow. This is not the fault of the app, it's the fault of Xamarin Forms.

  • JohnHJohnH GBMember ✭✭✭✭✭
    > @BlueRaja said:
    > @JohnHair The issue is that the startup time on an absolute barebones Xamarin Forms project is unreasonably slow. This is not the fault of the app, it's the fault of Xamarin Forms.

    iOS or Android? On release builds?
Sign In or Register to comment.