Let's talk performance

123457»

Posts

  • DanielRobbinsDanielRobbins USMember ✭✭

    General perception is that over the last 3 months, Xamarin is now performing noticeably faster in all areas. I'm on the alpha channel. It's a welcome improvement.

  • ValonKastValonKast USMember

    @DanielRobbins said:
    General perception is that over the last 3 months, Xamarin is now performing noticeably faster in all areas. I'm on the alpha channel. It's a welcome improvement.

    Yes, I'm also seeing improvements in Xamarin.Forms.I hope they release more Performance Updates in the Future rather than new Features.

  • PhilipGruebelePhilipGruebele USMember ✭✭

    Yes, on alpha channel our app is noticeably smoother, although startup times did not appear to change (our app is start-up optimized and launches in about 1.5 seconds though).

  • JosecanallaJosecanalla ARMember ✭✭

    Hello! I developed a Xamarin.Forms app using VS Community 2017 over Windows:

    • Xamarin.Forms version 2.3.4.270
    • I use Xamarin.Forms.Maps (not in main screen).
    • I have Multi-Dex enabled because of without enabling it I can't use Azure Mobile Center.
    • I have ProGuard disabled.
    • I have "SDK assemblies only" in linker.
    • I don't have splashscreen.
    • I have [assembly: XamlCompilation(XamlCompilationOptions.Compile)] above my PCL namespace.
    • The apk size is 17 MB.

    My app takes (release mode) about 5-6 s to open in a Android 7 smartphone (Moto G4 plus). And in an Android 4.4.2 phone takes 10 s.

    Is that normal?

  • NamyslawSzymaniukNamyslawSzymaniuk USMember ✭✭✭

    @Josecanalla said:
    Hello! I developed a Xamarin.Forms app using VS Community 2017 over Windows:

    • Xamarin.Forms version 2.3.4.270
    • I use Xamarin.Forms.Maps (not in main screen).
    • I have Multi-Dex enabled because of without enabling it I can't use Azure Mobile Center.
    • I have ProGuard disabled.
    • I have "SDK assemblies only" in linker.
    • I don't have splashscreen.
    • I have [assembly: XamlCompilation(XamlCompilationOptions.Compile)] above my PCL namespace.
    • The apk size is 17 MB.

    My app takes (release mode) about 5-6 s to open in a Android 7 smartphone (Moto G4 plus). And in an Android 4.4.2 phone takes 10 s.

    Is that normal?

    Unfortunately yes. Try to enable AOT - it reduces cold start of my app from 6 sec, to 3 sec at chinese Mediatek device.

  • MarcoTronconeMarcoTroncone GBUniversity ✭✭

    @ValonKast said:

    @DanielRobbins said:
    General perception is that over the last 3 months, Xamarin is now performing noticeably faster in all areas. I'm on the alpha channel. It's a welcome improvement.

    Yes, I'm also seeing improvements in Xamarin.Forms.I hope they release more Performance Updates in the Future rather than new Features.

    I agree. Xamarin Forms offers all the features that we need. The problem with it are the performances. Guys you are doing an amazing job but you really need to concentrate on performance improvements rather than new features.

  • MarcoTronconeMarcoTroncone GBUniversity ✭✭

    @rogihee said:
    Xamarin is beginning to measure startup times in the Jenkins logs, so a first step towards checking if commits have an performance impact by running NUnit tests on real devices (AFAICT):
    https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/plot/Tests%20times/

    This is something really important. It's a pity that for now there are no improvements but at least now we can see it there are improvements.

    I remember that once a guy from the team said that the starting times are so long because of all the things that Forms load automatically. I'm thinking that probably we don't need all the things that Forms is loading (especially form a small app). Why don't you give us the possibility to select before the Forms.Init which features we want to load and which ones we don't want? Maybe in this way we can reduce the starting times avoiding to load useless stuff.

  • JosecanallaJosecanalla ARMember ✭✭

    @NamyslawSzymaniuk said:

    @Josecanalla said:
    Hello! I developed a Xamarin.Forms app using VS Community 2017 over Windows:

    • Xamarin.Forms version 2.3.4.270
    • I use Xamarin.Forms.Maps (not in main screen).
    • I have Multi-Dex enabled because of without enabling it I can't use Azure Mobile Center.
    • I have ProGuard disabled.
    • I have "SDK assemblies only" in linker.
    • I don't have splashscreen.
    • I have [assembly: XamlCompilation(XamlCompilationOptions.Compile)] above my PCL namespace.
    • The apk size is 17 MB.

    My app takes (release mode) about 5-6 s to open in a Android 7 smartphone (Moto G4 plus). And in an Android 4.4.2 phone takes 10 s.

    Is that normal?

    Unfortunately yes. Try to enable AOT - it reduces cold start of my app from 6 sec, to 3 sec at chinese Mediatek device.

    Can I enable AOT without an enterprise license? I don't see the option under "Android options -> Packaging"

  • zahikramerzahikramer ILMember ✭✭✭

    @Josecanalla said:

    Can I enable AOT without an enterprise license? I don't see the option under "Android options -> Packaging"

    https://forums.xamarin.com/discussion/comment/284477/#Comment_284477

  • JosecanallaJosecanalla ARMember ✭✭

    @zahikramer thanks!
    @NamyslawSzymaniuk

    I enabled AOT for release, and also enabled LLVM and I reduce the startup time over 1 s. Is there another tip?

  • DanielRobbinsDanielRobbins USMember ✭✭

    @MarcoTroncone I think I half agree with you -- focus 49% on performance and 49% on ease-of-use for developers (documentation, clean and intuitive APIs), 2% on other things, and the community will be able to take care of the rest :)

  • DonBoxDonBox USMember ✭✭

    @EZHart @DavidOrtinau What is "Layout Compression" and how does it work? Can you please describe it a bit how it works? I saw some blog posts but it only mentions it improves speed and reduces memory footprint.

  • RobertDurfeeRobertDurfee USMember ✭✭

    AOT really does help tremendously with start up times. I don't know why it's an Enterprise only option. They need to make it available for everyone in the UI and get it out of "experimental" status. It does increase the size of the APK, but we countered that by removing the extra architectures that are checked by default.

    We enable AOT and LLVM in our CI builds in the msbuild command by adding:

    /p:AotAssemblies=true /p:EnableLLVM=true

  • DavidOrtinauDavidOrtinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @DonBox said:
    @EZHart @DavidOrtinau What is "Layout Compression" and how does it work? Can you please describe it a bit how it works? I saw some blog posts but it only mentions it improves speed and reduces memory footprint.

    I'll get a more detailed explanation, but at render time the wrapping view is removed. Your UI can be XAML, C#, or a combination.

    https://blog.xamarin.com/3-big-things-explore-xamarin-forms-2-5-0-pre-release/

    https://github.com/davidortinau/ProfileLayout

  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭

    Is performance actually a problem for anyone?

    We use a $90 Android tablet for testing and it runs fine.

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @Irreal
    You comment conjured smile on my face :wink:
    Joke beside... this thread should contain a lot of success messages from Xamarin to a faster .forms.
    Instead, there are many postings from users that try to find some workarounds to make .forms faster
    That's not what we (at least I) expect from this thread and is really a pity... :angry:

  • MarcoTronconeMarcoTroncone GBUniversity ✭✭

    @Irreal said:
    @MelbourneDeveloper

    Nah, performance is great for everyone, we've all just been joking around for the last year.

    :D :D :D

    @MelbourneDeveloper The startup time for Xam.Forms in Android is awful. Have you ever used a native app? it loads in less than a second while Xamarin Forms takes at least 3/4 seconds...
    I really love Xamarin but performances are a very big problem here.

    I think they should really stop to add new features and start improving performances and solving bugs.

  • DirkWilhelmDirkWilhelm USMember ✭✭✭

    Startup performance and general app performance are two different things.

    Even if your app starts slow, you might not have any performance problems when the app is running, and vice versa.

  • JohnHairJohnHair GBMember ✭✭✭✭

    My 2pence:
    My Droid app starts in less than a second, but then my first page isn't Xamarin Forms. The first time I open a forms page within the app I see a 2 second hit, thankfully only the first time. Opening subsequent forms pages is lightning quick.

  • MarcoTronconeMarcoTroncone GBUniversity ✭✭

    @JohnHair said:
    My 2pence:
    My Droid app starts in less than a second, but then my first page isn't Xamarin Forms. The first time I open a forms page within the app I see a 2 second hit, thankfully only the first time. Opening subsequent forms pages is lightning quick.

    because when you start your app I presume you don't call Forms.Init.
    When you then call the Init method, then it takes the famous couple of seconds.

    but still this shouldn't happen.

    Then regarding the general performances, especially on Android, Xamarin Forms is not fluid as the native one. Not bad but I know they can do better.

  • JohnHairJohnHair GBMember ✭✭✭✭

    @MarcoTroncone Actually Forms.Init is (almost) the first thing I do in my MainActivity, I then SetContentView with my first non XF page. Depending on what the user does next decides when I display the first XF page, and that is where I see the 2 second hit which I can manage if I feel the need to.

  • MelbourneDeveloperMelbourneDeveloper AUMember ✭✭✭

    @Irreal , @MarcoTroncone
    Firstly, so where are the objective benchmark tests? Is there a website somewhere where someone has attempted to recreate an Android app with similar functionality - one compiled in Java, and one compiled with Xamarin, and tested on the same devices?

    Secondly, startup time is only a small aspect of performance.

    @DirkWilhelm

    Startup performance and general app performance are two different things.
    Even if your app starts slow, you might not have any performance problems when the app is running, and vice versa.

    True. Startup time matters for a lot of people and I can see why people would be annoyed with the extra startup time, but if loading or whatever needs to be done at startup, moving that loading time to another part of the code only delays the inevitable. It doesn't mean that the entire app will perform better. So, the question is, is the startup process needlessly doing unnecessary things? Or, is it loading data that will be later used for something else, and reduce the time that that later operation is going to perform? The only way to answer this question is to create a sample app and step through the code, or use a profiler. I'm sure that if you take the time to do this, and you can prove where XF is wasting time, the Xamarin Team will thank you. Until that time, making general assertions about performance is unhelpful the the Xamarin team.

    Startup time is not really an issue for us. Devices are getting faster and 3-4 seconds is negligible . The question is whether the rest of the app is performing badly, and I'd have to say that it isn't. Xamarin Forms basically performs pretty well on the whole.

  • JKayJKay USMember ✭✭✭

    Layout Compression looks great. I can already see areas where I can use it in my application. Hoping along with Fast Renderers I can get Android page loading a lot faster. Maybe even on par with iOS

  • LyndonHugheyLyndonHughey USUniversity ✭✭✭

    Good points @ZenDroid
    Additionally, I'd like to see some way on how to best determine what assemblies are being stripped from your app. I don't have time to link assemblies, one by one, then spend minutes compiling to see if it took (and then rinse and repeat until success).

    Can we we have an apk reader or something to read an apk or ipa examine what references are included? It would be even better to have some dialog that displays what is being stripped, but I would imagine reading the output would be easier to implement.

    I know we can rename an apk to zip and view the contents. Does one of the contained classes have a view-able list of contained assemblies that we can reference against the assemblies in our nugets? This would give us a head start in knowing what assemblies (or classes or methods) are linked and which one we may want to explicitly skip linking.

  • ZenDroidZenDroid USMember ✭✭
    edited November 1

    Hi, @LyndonHughey. Apk analysis is not an easy process. For this there are special utilities - Bitdiffer and Linker Analyzer. But I have not tried them yet.

    I added "AndroidAotAdditionalArguments: no-write-symbols,nodebug" in my csproj. This reduced the size of my package by 9Mb. Old size -39 Mb, new size - 30 Mb. Time of the first start - 5 sec.

  • mrmiagi0101mrmiagi0101 DEMember ✭✭
    edited November 2

    I was able to reduce startTime of my app (In Android per Stopwatch class start in MainActivity Cons) from 6 sec to 2 sec on a Samsung A5 (2016) without AOT. The keyword is Threading. Because Pages in Forms are just Wrapper you can create your first Pages parallel in Threads.

    E.g.: My app decides to show a loginPage or show the mainLogicPage. In app.xaml.cs cons start threads for the pages and checks:
    `this.createLoginPageTask = Task.Run(() =>
    {
    this.initTranslationTask.Wait();
    this.loginPage = new LoginPage();
    this.loginPageInNavigationPage = new BaseNavigationPage(loginPage);
    });

      this.checkForStoredLoginTask = Task.Run(() =>
      {
        this.login = new Login();
        if (this.login.LookUpStoredLogin())
        {
          CreateAndStartTabbedPageTask();
    
          this.doLoginInTask = Task.Run(() =>
          {
            this.login.DoLogin().Wait();
          });
        }
      });`
    

    In "protected override void OnStart()" in App.xaml.cs you have to ensure tasks are ready (ios is faster...). Forms needs a MainPage after it returns from OnStart:

    `this.checkForStoredLoginTask.Wait();
    if (this.login.StoredLoginExists)
    {
    this.doLoginInTask.Wait();
    if (this.login.LastLoginAttemptResult == LoginResult.Ok)
    {
    this.ShowTabbedPage();
    return;
    }
    }

      this.createLoginPageTask.Wait();
    
      this.MainPage = this.loginPageInNavigationPage;`
    

    With this technique, Forms can do "LoadApplication(app)" while you are creating your pages an do your logic checks. It would also be possible to start the tasks before new App(), but then you have to take care about DependencyServices not ready...

    So basically:
    Do all your heavyload things like Page creating and DB/SecureStore reading in threads.

    And linking with "SDK and User Assemblies" is working. Just be carefully if you use bindings and reflection. Simplest way is to skip those assemblies.

  • ZenDroidZenDroid USMember ✭✭
    edited November 2

    Hi, @mrmiagi0101. I will try your method with Threading. But option "SDK and User Assemblies" is not working for me. I have this exception:

       10-30 20:25:18.895 I/MonoDroid(12805): UNHANDLED EXCEPTION:
      Thread started: <Thread Pool> #9
       10-30 20:25:19.023 I/MonoDroid(12805): System.NullReferenceException: Object reference not set to an instance of an 
       object.
       10-30 20:25:19.023 I/MonoDroid(12805):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.LayoutRootPage 
       (Xamarin.Forms.Page page, System.Int32 width, System.Int32 height) [0x00034] in 
       <375f0348c53348fdb7c0a424087b45cb>:0 
       10-30 20:25:19.023 I/MonoDroid(12805):   at 
       Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout 
       (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0000a] in 
      <375f0348c53348fdb7c0a424087b45cb>:0 
      10-30 20:25:19.023 I/MonoDroid(12805):   at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout 
      (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00018] in 
      <375f0348c53348fdb7c0a424087b45cb>:0 
      10-30 20:25:19.023 I/MonoDroid(12805):   at Android.Views.ViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, 
      System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [ 
      0x00008] in <241e52499950417a9f098f3fc184c7de>:0 
     10-30 20:25:19.023 I/MonoDroid(12805):   at (wrapper dynamic-method) System.Object:28e70870-796b-47c6-a7d7-
     29a2619bac5a (intptr,intptr,bool,int,int,int,int)
     10-30 20:25:19.066 W/art     (12805): JNI RegisterNativeMethods: attempt to register 0 native methods for 
      android.runtime.JavaProxyThrowable
    

    I have problem with level Xamarin Core. I added in my csproj

    <AndroidLinkSkip>Xamarin.Android.Support.v7.AppCompat;Xamarin.Forms.Platform.Android</AndroidLinkSkip>
    

    But I have same exception.
    Maybe you can create MVP app (with Threading and "SDK and User Assemblies") on Git? It will be great.
    Thank you ideas.

  • mrmiagi0101mrmiagi0101 DEMember ✭✭

    I tried to reproduce your error with an new app (Just one page), but without sucess. It is working with all linking. This is the code where your exception is raised:
    void LayoutRootPage(Page page, int width, int height)
    {
    var activity = (FormsAppCompatActivity)_context;
    page.Layout(new Rectangle(0, 0, activity.FromPixels(width), activity.FromPixels(height)));
    }

    Only two possibilities: Page is null (this comes from App.MainPage Property) or _context is null.

    But I get the same error if I don't set the "App.MainPage" Property. So I guess your MainPage never gets set. First I would try to linkskip your two main assemblies, e.g.: YourAppName;YourAppName.Android.

    Skipping Xamarin assemblies is never necessary.

  • DnielBugaDnielBuga USMember ✭✭

    @mrmiagi0101 said:
    I was able to reduce startTime of my app (In Android per Stopwatch class start in MainActivity Cons) from 6 sec to 2 sec on a Samsung A5 (2016) without AOT. The keyword is Threading. Because Pages in Forms are just Wrapper you can create your first Pages parallel in Threads.
    With this technique, Forms can do "LoadApplication(app)" while you are creating your pages an do your logic checks. It would also be possible to start the tasks before new App(), but then you have to take care about DependencyServices not ready...

    So basically:
    Do all your heavyload things like Page creating and DB/SecureStore reading in threads.

    So by itself this technique did not result in any improvement in my app, but I'll leave it in there, just in case it means something on different devices. FYI, this thing crashes on windows platforms because MainPage is accessed before OnStart is called so extra logic is needed there.

  • mrmiagi0101mrmiagi0101 DEMember ✭✭

    @DnielBuga said:

    @mrmiagi0101 said:
    I was able to reduce startTime of my app (In Android per Stopwatch class start in MainActivity Cons) from 6 sec to 2 sec on a Samsung A5 (2016) without AOT. The keyword is Threading. Because Pages in Forms are just Wrapper you can create your first Pages parallel in Threads.
    With this technique, Forms can do "LoadApplication(app)" while you are creating your pages an do your logic checks. It would also be possible to start the tasks before new App(), but then you have to take care about DependencyServices not ready...

    So basically:
    Do all your heavyload things like Page creating and DB/SecureStore reading in threads.

    So by itself this technique did not result in any improvement in my app, but I'll leave it in there, just in case it means something on different devices. FYI, this thing crashes on windows platforms because MainPage is accessed before OnStart is called so extra logic is needed there.

    Ok. It depends on what you are doing on startup and how many core/threads you app gets on a specific device.
    Maybe you can show some code what you are doing.

    I had huge improvements on all my testdevices (LG G6, Samsung S5, S3, H. P9) and very small improvements on ios. UWP, I don't use...

    How do you measure the startup Time?

  • ReinVReinV BEMember ✭✭
    edited November 3

    @DnielBuga said:

    @mrmiagi0101 said:
    I was able to reduce startTime of my app (In Android per Stopwatch class start in MainActivity Cons) from 6 sec to 2 sec on a Samsung A5 (2016) without AOT. The keyword is Threading. Because Pages in Forms are just Wrapper you can create your first Pages parallel in Threads.
    With this technique, Forms can do "LoadApplication(app)" while you are creating your pages an do your logic checks. It would also be possible to start the tasks before new App(), but then you have to take care about DependencyServices not ready...

    So basically:
    Do all your heavyload things like Page creating and DB/SecureStore reading in threads.

    So by itself this technique did not result in any improvement in my app, but I'll leave it in there, just in case it means something on different devices. FYI, this thing crashes on windows platforms because MainPage is accessed before OnStart is called so extra logic is needed there.

    Have you tried the 'solution' I posted a while ago:

    https://forums.xamarin.com/discussion/comment/292925/#Comment_292925

    It is very similar to what is described here, we had some great results with it. (User perceived)

  • JKayJKay USMember ✭✭✭

    Has anyone tried LayoutCompression yet?

    I find in my app that first time showing a page it takes longer than the subsequent times. even when I'm not caching anythine? xamarin.Forms must be doing some caching of some kind

  • PhilipGruebelePhilipGruebele USMember ✭✭

    Using similar techniques our app launches to showing the full UI in about 1.6s on higher end phones. There have been some other posts here about startup optimization and I think if you follow all the recommendations you can achieve reasonable timing. The key is to use threading and lazy initialization so that the main UI can open as quickly as possible. In order to solve timing/corner cases the UI thread needs to await some threaded tasks in the appropriate places - once again as late as possible. Certainly things like database and file IO should NEVER run on the UI thread even post-launch. It's quite a bit of work though :(

  • DavidOrtinauDavidOrtinau USForum Administrator, Xamarin Team, Insider, University Xamurai

    @JKay said:
    Has anyone tried LayoutCompression yet?

    I find in my app that first time showing a page it takes longer than the subsequent times. even when I'm not caching anythine? xamarin.Forms must be doing some caching of some kind

    Interesting. By a factor of what? This is visibly slower or are you measuring something? Also, just to confirm you have XAMLC enabled and are running in release mode?

    Send me a sample with some guidance on what you're testing if you can.

  • JKayJKay USMember ✭✭✭

    @DavidOrtinau This is just visibly slower. I'm not measuring it at the moment. I have got XAMLC enabled.

    I need to do more investigation into it because it may not be Xamarins issue.
    I use Popup Page for most of my navigation so it could be that, or it could be me making too many database calls.

    If after my investigation I still find Its not something I can fix I'll put a sample together and send it your way

  • BradChase.2654BradChase.2654 USMember ✭✭✭

    @JKay I have admittedly not been following the layout compression stuff, but in terms of finding the culprits on performance bottlenecks, have you tried using VS2017's built in profiiler? Our app is too large for Xamarin's performance profiler and bombs it out so we use VS2017's now.

    It is really fantastic... could have better features but it does the job. Only down fall is it only works with UWP that I know of :(.

123457»
Sign In or Register to comment.