locked
Xamarin Forms every thing is slow RRS feed

  • Question

  • User261196 posted

    Hello friends i had built a xamarin form app for android i use mvvm pattern to built it , i use lazy loading in all pages there is only a few icons in resources folder but the app is very slow from opening the app to the navigation even if the page is empty i heard the this was a problem in 2014 but we are now 2019 but i google it i never found the solution .

    please any help thanks

    Saturday, September 28, 2019 1:10 AM

Answers

  • User176749 posted

    you probably didnt google enough. > @AlbertK said:

    Well it is big and slow. But you get C# :smile:

    it is a cross platform solution, you cannot expect same size and performance as native java and swift performance. But app size is smaller than flutter and react native if you want to compare in same league. Regarding performance, yes you can reach almost native performance. you need to google more. there are dozens of articles and hints given to the community. In Debug running, it might be slow but it is debug right. in Release, you must use AOT+LLVM to get faster start up time and better performance. There are many other improvement tips on listview, xaml etc. etc. you can google them.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, September 28, 2019 11:47 AM
  • User176749 posted

    @AlbertK said: @aliZAKRIA Support for AOT+LLVM it is VS Enterprise edition only if I am not mistaken. At the moment with VS 2019 16.3 you can "Enable Startup Tracing" which will speed up the startup time but increases the app size.

    enterprise only is about settings using visual studio but you can open droid.csproj file and manually add the lines and build. it will work. here is a full release settings for you to use.

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <Optimize>false</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>     
        <AndroidLinkMode>Full</AndroidLinkMode>
        <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
        <AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi>
        <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
        <AotAssemblies>false</AotAssemblies>
        <AndroidAotAdditionalArguments>no-write-symbols,nodebug</AndroidAotAdditionalArguments>
        <DebugSymbols>false</DebugSymbols>
        <BundleAssemblies>true</BundleAssemblies>
        <Debugger>Xamarin</Debugger>
        <AndroidEnableMultipleDex>true</AndroidEnableMultipleDex>
        <AndroidExplicitCrunch>false</AndroidExplicitCrunch>        
        <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
        <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
        <AndroidSupportedAbis>x86;x86_64;arm64-v8a;armeabi-v7a</AndroidSupportedAbis>
        <EnableLLVM>true</EnableLLVM>
        <AndroidUseAapt2>false</AndroidUseAapt2>
        <AndroidDexTool>dx</AndroidDexTool>
        <AndroidLinkTool>proguard</AndroidLinkTool>
      </PropertyGroup>
    

    be careful with AndroidLinkMode and AndroidLinkTool as proguard, it will cause you build errors if you dont do it correctly. if you use AndroidEnableProfiledAot=true, it will override AotAssemblies. so you can use either of them as true. AotAssemblies=true * makes android start up time faster and app perfomance is better. disadvantage app size is 10mb+ bigger *AndroidEnableProfiledAot=true improves only android start up time faster but doesnt improve app performance. app size is 10+ mb smaller. in my experience, if you are doing everything correct, your UI isnt very complicated with unnecessary stuffs and you are doing too much on UI theread. So basically if you code clearn. performance difference between AotAssemblies and AndroidEnableProfiledAot not very significant. thats why i prefer AndroidEnableProfiledAot to gain app size. I hope this helps you. these are all documented nicely in microsoft documentation, please read through. PS; AndroidUseAapt2 should be true also but xamarin had a bug and currently i disabled it. it has also performance advantage. Some people uses instead of dx, d8 and instead of proguard, r8 but i havent tried it long time. it helps to increase performance and reduce app size as well. earlier stage d8 and r8 had problems but xamarin team improved it.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, September 29, 2019 12:07 PM

All replies

  • User228975 posted

    Well it is big and slow. But you get C# :smile:

    Saturday, September 28, 2019 1:19 AM
  • User176749 posted

    you probably didnt google enough. > @AlbertK said:

    Well it is big and slow. But you get C# :smile:

    it is a cross platform solution, you cannot expect same size and performance as native java and swift performance. But app size is smaller than flutter and react native if you want to compare in same league. Regarding performance, yes you can reach almost native performance. you need to google more. there are dozens of articles and hints given to the community. In Debug running, it might be slow but it is debug right. in Release, you must use AOT+LLVM to get faster start up time and better performance. There are many other improvement tips on listview, xaml etc. etc. you can google them.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, September 28, 2019 11:47 AM
  • User261196 posted

    @batmaci said: you probably didnt google enough. > @AlbertK said:

    Well it is big and slow. But you get C# :smile:

    it is a cross platform solution, you cannot expect same size and performance as native java and swift performance. But app size is smaller than flutter and react native if you want to compare in same league. Regarding performance, yes you can reach almost native performance. you need to google more. there are dozens of articles and hints given to the community. In Debug running, it might be slow but it is debug right. in Release, you must use AOT+LLVM to get faster start up time and better performance. There are many other improvement tips on listview, xaml etc. etc. you can google them.

    thanks man for your positive replay , i am a beginner in xamarin framework that why i ask i saw super fast app built with xamarin that why i decide to use it , could you tell me how to activate AOT+LLVM this first time i heard about it thanks man again

    Saturday, September 28, 2019 2:50 PM
  • User228975 posted

    @aliZAKRIA Support for AOT+LLVM it is VS Enterprise edition only if I am not mistaken. At the moment with VS 2019 16.3 you can "Enable Startup Tracing" which will speed up the startup time but increases the app size.

    Sunday, September 29, 2019 12:01 AM
  • User176749 posted

    @AlbertK said: @aliZAKRIA Support for AOT+LLVM it is VS Enterprise edition only if I am not mistaken. At the moment with VS 2019 16.3 you can "Enable Startup Tracing" which will speed up the startup time but increases the app size.

    enterprise only is about settings using visual studio but you can open droid.csproj file and manually add the lines and build. it will work. here is a full release settings for you to use.

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <Optimize>false</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>     
        <AndroidLinkMode>Full</AndroidLinkMode>
        <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
        <AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi>
        <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
        <AotAssemblies>false</AotAssemblies>
        <AndroidAotAdditionalArguments>no-write-symbols,nodebug</AndroidAotAdditionalArguments>
        <DebugSymbols>false</DebugSymbols>
        <BundleAssemblies>true</BundleAssemblies>
        <Debugger>Xamarin</Debugger>
        <AndroidEnableMultipleDex>true</AndroidEnableMultipleDex>
        <AndroidExplicitCrunch>false</AndroidExplicitCrunch>        
        <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
        <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
        <AndroidSupportedAbis>x86;x86_64;arm64-v8a;armeabi-v7a</AndroidSupportedAbis>
        <EnableLLVM>true</EnableLLVM>
        <AndroidUseAapt2>false</AndroidUseAapt2>
        <AndroidDexTool>dx</AndroidDexTool>
        <AndroidLinkTool>proguard</AndroidLinkTool>
      </PropertyGroup>
    

    be careful with AndroidLinkMode and AndroidLinkTool as proguard, it will cause you build errors if you dont do it correctly. if you use AndroidEnableProfiledAot=true, it will override AotAssemblies. so you can use either of them as true. AotAssemblies=true * makes android start up time faster and app perfomance is better. disadvantage app size is 10mb+ bigger *AndroidEnableProfiledAot=true improves only android start up time faster but doesnt improve app performance. app size is 10+ mb smaller. in my experience, if you are doing everything correct, your UI isnt very complicated with unnecessary stuffs and you are doing too much on UI theread. So basically if you code clearn. performance difference between AotAssemblies and AndroidEnableProfiledAot not very significant. thats why i prefer AndroidEnableProfiledAot to gain app size. I hope this helps you. these are all documented nicely in microsoft documentation, please read through. PS; AndroidUseAapt2 should be true also but xamarin had a bug and currently i disabled it. it has also performance advantage. Some people uses instead of dx, d8 and instead of proguard, r8 but i havent tried it long time. it helps to increase performance and reduce app size as well. earlier stage d8 and r8 had problems but xamarin team improved it.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, September 29, 2019 12:07 PM
  • User261196 posted

    @batmaci said:

    @AlbertK said: @aliZAKRIA Support for AOT+LLVM it is VS Enterprise edition only if I am not mistaken. At the moment with VS 2019 16.3 you can "Enable Startup Tracing" which will speed up the startup time but increases the app size.

    enterprise only is about settings using visual studio but you can open droid.csproj file and manually add the lines and build. it will work. here is a full release settings for you to use.

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <Optimize>false</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>     
        <AndroidLinkMode>Full</AndroidLinkMode>
        <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
        <AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi>
        <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
        <AotAssemblies>false</AotAssemblies>
        <AndroidAotAdditionalArguments>no-write-symbols,nodebug</AndroidAotAdditionalArguments>
        <DebugSymbols>false</DebugSymbols>
        <BundleAssemblies>true</BundleAssemblies>
        <Debugger>Xamarin</Debugger>
        <AndroidEnableMultipleDex>true</AndroidEnableMultipleDex>
        <AndroidExplicitCrunch>false</AndroidExplicitCrunch>        
        <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
        <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
        <AndroidSupportedAbis>x86;x86_64;arm64-v8a;armeabi-v7a</AndroidSupportedAbis>
        <EnableLLVM>true</EnableLLVM>
        <AndroidUseAapt2>false</AndroidUseAapt2>
        <AndroidDexTool>dx</AndroidDexTool>
        <AndroidLinkTool>proguard</AndroidLinkTool>
      </PropertyGroup>
    

    be careful with AndroidLinkMode and AndroidLinkTool as proguard, it will cause you build errors if you dont do it correctly. if you use AndroidEnableProfiledAot=true, it will override AotAssemblies. so you can use either of them as true. AotAssemblies=true * makes android start up time faster and app perfomance is better. disadvantage app size is 10mb+ bigger *AndroidEnableProfiledAot=true improves only android start up time faster but doesnt improve app performance. app size is 10+ mb smaller. in my experience, if you are doing everything correct, your UI isnt very complicated with unnecessary stuffs and you are doing too much on UI theread. So basically if you code clearn. performance difference between AotAssemblies and AndroidEnableProfiledAot not very significant. thats why i prefer AndroidEnableProfiledAot to gain app size. I hope this helps you. these are all documented nicely in microsoft documentation, please read through. PS; AndroidUseAapt2 should be true also but xamarin had a bug and currently i disabled it. it has also performance advantage. Some people uses instead of dx, d8 and instead of proguard, r8 but i havent tried it long time. it helps to increase performance and reduce app size as well. earlier stage d8 and r8 had problems but xamarin team improved it. Thanks very much man i will try it

    Monday, September 30, 2019 12:27 AM
  • User380290 posted

    @batmaci said:

    @AlbertK said: @aliZAKRIA Support for AOT+LLVM it is VS Enterprise edition only if I am not mistaken. At the moment with VS 2019 16.3 you can "Enable Startup Tracing" which will speed up the startup time but increases the app size.

    enterprise only is about settings using visual studio but you can open droid.csproj file and manually add the lines and build. it will work. here is a full release settings for you to use.

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <Optimize>false</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>     
        <AndroidLinkMode>Full</AndroidLinkMode>
        <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
        <AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi>
        <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
        <AotAssemblies>false</AotAssemblies>
        <AndroidAotAdditionalArguments>no-write-symbols,nodebug</AndroidAotAdditionalArguments>
        <DebugSymbols>false</DebugSymbols>
        <BundleAssemblies>true</BundleAssemblies>
        <Debugger>Xamarin</Debugger>
        <AndroidEnableMultipleDex>true</AndroidEnableMultipleDex>
        <AndroidExplicitCrunch>false</AndroidExplicitCrunch>        
        <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot>
        <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
        <AndroidSupportedAbis>x86;x86_64;arm64-v8a;armeabi-v7a</AndroidSupportedAbis>
        <EnableLLVM>true</EnableLLVM>
        <AndroidUseAapt2>false</AndroidUseAapt2>
        <AndroidDexTool>dx</AndroidDexTool>
        <AndroidLinkTool>proguard</AndroidLinkTool>
      </PropertyGroup>
    

    be careful ...

    Thank you for those tips, may I ask though why would you set false? Is this just a copy-pase mistake or does it really produce better results? I image it must do the opposite.

    Friday, April 2, 2021 1:30 PM
  • User176749 posted

    @DanielKraut which setting do you ask?

    Friday, April 2, 2021 2:44 PM
  • User380290 posted

    @batmaci said: @DanielKraut which setting do you ask?

    I am sorry I didn't realised that XML tags were automatically deleted from my post. I asked about:

    xml <Optimize>false</Optimize>

    Friday, April 2, 2021 5:16 PM
  • User176749 posted

    @DanielKraut good question. I am not sure if that makes any difference building on APK. it is pure .net optimization seems to be according to the documentation. I had somewhere in github a discussion about it with a Xamarin employee and he suggested that back in the days if i recall correctly but we can re-raise the question. Do you see any benefits of Optimize=true? I guess that this was also default VS2019 template "false" earlier.

    https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2017

    Friday, April 2, 2021 5:24 PM
  • User380290 posted

    @batmaci said: Do you see any benefits of Optimize=true? I guess that this was also default VS2019 template "false" earlier.

    Well I don't have much experience with different compilation settings. During compilation of Xamarin projects I think that first are C# source files compiled to DLLs so I imagined it would optimize the code at least in this phase. But I haven't really done any comparisons of release build different flags yet as we are still in first development cycle I am just doing a little bit of research about how to optimize the produced build. I will do more testing in a few weeks when we will release our application to production.

    Your original post is from 2019 and I see that you used proguard and dx. Do you think they are still relevant or are D8 and R8 better now? I tried the settings you posted and I had to change to this:

    xml <AndroidDexTool>d8</AndroidDexTool> <AndroidLinkTool>r8</AndroidLinkTool> <AndroidUseAapt2>true</AndroidUseAapt2>

    Otherwise I would get compilation errors. See this: https://forums.xamarin.com/discussion/184792/error-apt1000-found-tag-id-where-item-is-expected-apt1000-swlog-android

    Friday, April 2, 2021 5:55 PM
  • User176749 posted

    @DanielKraut no it is not. I have already switched to d8 and r8. Earlier it didnt work well but Xamarin team fixed the problems and It works for me. You have to be careful with r8 because it is more aggressive than proguard and removes more stuffs. You need to adjust your proguard.cfg ile further. it is bit confusing indeed because when you use r8, you still use proguard file :)

    yes this is my current settings

    <AndroidDexTool>d8</AndroidDexTool> <AndroidLinkTool>r8</AndroidLinkTool> <AndroidUseAapt2>true</AndroidUseAapt2>

    Tuesday, April 6, 2021 4:36 PM