Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAUI very slow on physical android devices #18838

Open
OpterJohan-Hallberg opened this issue Nov 17, 2023 · 49 comments
Open

MAUI very slow on physical android devices #18838

OpterJohan-Hallberg opened this issue Nov 17, 2023 · 49 comments
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions delighter legacy-area-perf Startup / Runtime performance migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Milestone

Comments

@OpterJohan-Hallberg
Copy link

Description

MAUI Android runs very well on emulators, but on physical devices, both debug and release it runs very slow. I believe its due to an error that gets throw due to a variety of reasons, that gets worse the more content a project has. I'm our current project just switching to another page can take up to 10 or so seconds, on a new MAUI project it isn't noticeable, but its there still. This did not use to take that long i Xamarin. Its unusable with that much delay on pretty much everything.

The errors always look something similar to this:
[monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'androidx/fragment/app/FragmentManagerImpl' [monodroid-assembly] typemap: called from [monodroid-assembly] at Java.Interop.TypeManager.GetJavaToManagedType(String class_name) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 228 [monodroid-assembly] at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 274 [monodroid-assembly] at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 303 [monodroid-assembly] at Java.Lang.Object._GetObject[Frag

It can be reproduced in a completely new and untouched MAUI project too:
[monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'com/android/internal/policy/PhoneLayoutInflater' [monodroid-assembly] typemap: called from [monodroid-assembly] at Java.Interop.TypeManager.GetJavaToManagedType(String class_name) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 230 [monodroid-assembly] at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 274 [monodroid-assembly] at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 304 [monodroid-assembly] at Java.Lang.Object._GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 290 [monodroid-assembly] at Java.Lang.Object.GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 281 [monodroid-assembly] at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 2028 [monodroid-assembly] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 352 [monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'androidx/fragment/app/FragmentManagerImpl' [monodroid-assembly] typemap: called from [monodroid-assembly] at Java.Interop.TypeManager.GetJavaToManagedType(String class_name) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 230 [monodroid-assembly] at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 274 [monodroid-assembly] at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 304 [monodroid-assembly] at Java.Lang.Object._GetObject[FragmentManager](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 290 [monodroid-assembly] at Java.Lang.Object.GetObject[FragmentManager](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 281 [monodroid-assembly] at AndroidX.Fragment.App.Fragment.get_ChildFragmentManager() in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 416 [monodroid-assembly] at Microsoft.Maui.Controls.Platform.Compatibility.ShellFragmentContainer.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFragmentContainer.cs:line 48 [monodroid-assembly] at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 2031 [monodroid-assembly] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 352 [Mono] Running class .cctor for Microsoft.Maui.Handlers.PageHandler from '/data/data/com.companyname.mauiapp3test/files/.__override__/Microsoft.Maui.dll' [Mono] Running class .cctor for Microsoft.Maui.Handlers.ContentViewHandler from '/data/data/com.companyname.mauiapp3test/files/.__override__/Microsoft.Maui.dll'

Steps to Reproduce

  1. Create a new .Net MAUI App
  2. Start debug to physical device.
  3. Give i a moment after it launches
  4. `[monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'com/android/internal/policy/PhoneLayoutInflater' error will appear in debug log.

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 and up at least.

Did you find any workaround?

We have not been able to find a workaround.

Relevant log output

[monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'com/android/internal/policy/PhoneLayoutInflater'
[monodroid-assembly] typemap: called from
[monodroid-assembly] at Java.Interop.TypeManager.GetJavaToManagedType(String class_name) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 230
[monodroid-assembly]    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 274
[monodroid-assembly]    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 304
[monodroid-assembly]    at Java.Lang.Object._GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 290
[monodroid-assembly]    at Java.Lang.Object.GetObject[LayoutInflater](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 281
[monodroid-assembly]    at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 2028
[monodroid-assembly]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 352
[monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'androidx/fragment/app/FragmentManagerImpl'
[monodroid-assembly] typemap: called from
[monodroid-assembly] at Java.Interop.TypeManager.GetJavaToManagedType(String class_name) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 230
[monodroid-assembly]    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 274
[monodroid-assembly]    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 304
[monodroid-assembly]    at Java.Lang.Object._GetObject[FragmentManager](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 290
[monodroid-assembly]    at Java.Lang.Object.GetObject[FragmentManager](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 281
[monodroid-assembly]    at AndroidX.Fragment.App.Fragment.get_ChildFragmentManager() in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 416
[monodroid-assembly]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellFragmentContainer.OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFragmentContainer.cs:line 48
[monodroid-assembly]    at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 2031
[monodroid-assembly]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L(_JniMarshal_PPLLL_L callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1, IntPtr p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 352
@OpterJohan-Hallberg OpterJohan-Hallberg added the t/bug Something isn't working label Nov 17, 2023
@Eilon Eilon added the legacy-area-perf Startup / Runtime performance label Nov 17, 2023
@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Dec 6, 2023
@VNGames
Copy link

VNGames commented Dec 12, 2023

For me it is also very slow without any prints like reporter has here, on Android 12. I migrated (manually = creating the same app by moving pieces of code and rewriting renderers into handlers etc) an app from Xamarin and it is very slow on device.
Even a simple page takes a few seconds (5 and more) to open. And the only prints Debug does during that time is GC
Explicit concurrent copying GC freed 7731(487KB) AllocSpace objects, 0(0B) LOS objects, 80% free, 6090KB/29MB, paused 57us,41us total 35.242ms
Which is not critical and isn't a reason to delay for 5 sec for a simple page.
I use NET 8 and MAUI 8.0.3.
On Emulator it runs ok.

In DEBUG. In RELEASE everything is ok.
Turning off Hot reload didn't help.

@asi-evin
Copy link

asi-evin commented Jan 18, 2024

I can confirm I am getting these messages all the time in debug. Common ones include (but not limited to):

  • typemap: unable to find mapping to a managed type from Java type 'androidx/fragment/app/FragmentManagerImpl'
  • typemap: unable to find mapping to a managed type from Java type 'android/app/SharedPreferencesImpl'
  • typemap: unable to find mapping to a managed type from Java type 'android/app/ApplicationPackageManager'
  • typemap: unable to find mapping to a managed type from Java type 'com/android/internal/policy/PhoneLayoutInflater'
  • typemap: unable to find mapping to a managed type from Java type 'android/view/WindowManagerImpl'

That last one happens VERY often as it's triggered by getting the main display DPI in a looped animation (at Microsoft.Maui.Devices.DeviceDisplayImplementationBase.get_MainDisplayInfo()).

It makes it nearly impossible to find debug messages in the console.

Edit: Thought I should add, it appears to be device specific: My TCL 30XE running Android 12 does not have this problem, but my Samsung A13 running Android 13 excretes this issue like sweat in a texas summer.

Edit 2: Nvm, my TCL now has these issues...

@South2AK
Copy link

Having the same problem. Any news to this?

@pboisso
Copy link

pboisso commented Mar 12, 2024

Same here.

@rudyspano
Copy link

Forcing xaml compilation results in same performance as Xamarin Forms in our side in Debug. (Breaks Xaml Hot Reload for the moment)
https://www.sharpnado.com/net-maui-painfully-slow-debugging/?fbclid=IwAR0_aHJXi0OBoh8VO7gdn_u2AJcRBETKqgM05MnsaomaCmsFCnbq-GDGaBI

@clintcambier
Copy link

Also from our end there is a major difference in which physical Android devices are about 5 times slower than Android emulators AND iOS physical devices.

This is a critical problem that does not seem to be on the radar at all. Who should we contact to escalate this further?

@QiteSimon
Copy link

I'm having trouble with this as well.
My app, which was migrated from Xamarin, is MUCH slower in MAUI than in Xamarin.
At least it is on Android. iOS seems to be running just fine.

@VNGames
Copy link

VNGames commented Mar 25, 2024

@clintcambier @QiteSimon Did you try solution in the post above yours?

Adding this for DEBUG should solve slowness
<_MauiForceXamlCForDebug>true</_MauiForceXamlCForDebug>
(I didn't try yet, Just asking but it seems like this should be the solution. In Production my app isn't slow at all. I would say even faster than Xamarin, But during DEBUG it is slow on a physical device Android and article above says it is because in MAUI xaml compilation is turned off by default)

@QiteSimon
Copy link

The performance while debugging is acceptable (slower yes, but ok).
It's the production build that goes much slower and is not acceptable for our users.

@catnip050
Copy link

The same problem exists.
<_MauiForceXamlCForDebug>true</_MauiForceXamlCForDebug> did not solve the problem.
Has anyone made any progress?

@mnxamdev
Copy link

I'm having trouble with this as well. My app, which was migrated from Xamarin, is MUCH slower in MAUI than in Xamarin. At least it is on Android. iOS seems to be running just fine.

Same here but to a lesser degree on iOS as it's definitely not as snappy as Xamarin.Forms on iOS. Our project on Xamarin.Forms in Android is much more performant yet Xamarin.Forms support is End of Life in 5 days. Menu drawer closing while navigating is supper laggy as well as everything else so much so that we can't even develop properly. Again, these issues are also apparent in Release mode and we can't release to production with these serious performance issues. They exist in our app in debug and release in MAUI but not Xamarin.Forms. Microsoft needs to extend Xamarin.Forms support until MAUI is stable and performant as the product they intend to be replacing.

@clintcambier
Copy link

clintcambier commented Apr 26, 2024 via email

@rudyspano
Copy link

@mnxamdev, my advice: I know that can be time consuming but you should create small projects to isolate each problem that you suspect. I personnaly don't use "Menu Drawer" for instance.
If you can reproduce your performance issues in small projects that you can share and create Github issue Microsoft and the community will help you...

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 30, 2024
@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio 17.10 Preview 5 (8.0.21&8.0.3). Can repro on android device platform.
image

@PureWeen
Copy link
Member

@Eilon Eilon added the t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) label May 10, 2024
@PureWeen PureWeen added the area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions label May 31, 2024
@PureWeen
Copy link
Member

@jonathanpeppers thoughts?

@SKeehnen
Copy link

SKeehnen commented Jun 4, 2024

A solution would be great, not only makes it the app slower but also produces an unreadable debug window. I'm using many settings through the Preferences, so my debug window is completely filled with these messages:

[monodroid-assembly] typemap: unable to find mapping to a managed type from Java type 'android/app/SharedPreferencesImpl' [monodroid-assembly] typemap: called from [monodroid-assembly] at Java.Interop.TypeManager.GetJavaToManagedType(String class_name) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 228 [monodroid-assembly] at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:line 274 [monodroid-assembly] at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 303 [monodroid-assembly] at Java.Lang.Object._GetObject[ISharedPreferences](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 289 [monodroid-assembly] at Java.Lang.Object.GetObject[ISharedPreferences](IntPtr handle, JniHandleOwnership transfer) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:line 281 [monodroid-assembly] at Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(Context context) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Preferences.PreferenceManager.cs:line 886 [monodroid-assembly] at Microsoft.Maui.Storage.PreferencesImplementation.GetSharedPreferences(String sharedName) in D:\a\_work\1\s\src\Essentials\src\Preferences\Preferences.android.cs:line 160 [monodroid-assembly] at Microsoft.Maui.Storage.PreferencesImplementation.Get[Int32](String key, Int32 defaultValue, String sharedName) in D:\a\_work\1\s\src\Essentials\src\Preferences\Preferences.android.cs:line 99 [monodroid-assembly] at Microsoft.Maui.Storage.Preferences.Get(String key, Int32 defaultValue, String sharedName) in D:\a\_work\1\s\src\Essentials\src\Preferences\Preferences.shared.cs:line 185 [monodroid-assembly] at Microsoft.Maui.Storage.Preferences.Get(String key, Int32 defaultValue) in D:\a\_work\1\s\src\Essentials\src\Preferences\Preferences.shared.cs:line 116

@jonathanpeppers
Copy link
Member

The monodroid-assembly log messages are not on by default. Did you run a command like this to enable them?

adb shell setprop debug.mono.log assembly

Simply enabling log messages like these will make the app slower. setprop doesn't clear unless you reboot the device, but you can clear it with:

adb shell setprop debug.mono.log "''"

@SKeehnen
Copy link

SKeehnen commented Jun 10, 2024

Thanks @jonathanpeppers that worked perfect!
At least the debug window is readable again and the performance is better, but still worse then running in debug mode using Xamarin.

@jsuarezruiz jsuarezruiz added this to the Triaged milestone Jun 13, 2024
@wagaana
Copy link

wagaana commented Jun 15, 2024

My app was working well in .net 7.0 preview, but after upgrading it to .net 8.0, the app got slow on Android.

@jonathanpeppers
Copy link
Member

@wagaana did you profile your app? If you could share a sample project or .speedscope file: https://aka.ms/profile-maui

I don't know of any performance regression going from .NET 7 to .NET 8.

@zkolar
Copy link

zkolar commented Sep 6, 2024

Any news here? Have same problem, in emulator is ok, but on physical android device unusable

@jonathanpeppers
Copy link
Member

Any news here? Have same problem, in emulator is ok, but on physical android device unusable

This sounds backwards to me: my experience is that something like even a Pixel 5 (few years old) is faster than an emulator.

If someone is able to review https://aka.ms/profile-maui and share .speedscope files of the slowdown we can investigate. Thanks!

@jonathanpeppers jonathanpeppers added the s/needs-info Issue needs more info from the author label Sep 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Sep 11, 2024
@RafaRioFal4699
Copy link

Same here, since I migrated my project from Xamarin.Forms to MAUI, I've noticed a big drop in productivity. Despite the fact that MAUI was relased two years ago, it feels a very beta (almost alpha) version of the product that Microsoft promised. Is two, three or four steps behind the obsolete version of Xamarin.Forms.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity labels Sep 12, 2024
@dijonsmit
Copy link

Also experiencing the same issue, Android version of our app is extremely laggy and will give our customers very bad experience and not good for the companies reputation.

@marcmarsinach
Copy link

marcmarsinach commented Oct 18, 2024 via email

@KevThompson2020
Copy link

Same issue here. CollectionView click can take something like half a second if not more to register on Android ( Pixel 7 so not exactly a slow device ). IOS, Windows, Mac are all fine.

@jonathanpeppers
Copy link
Member

Same issue here. CollectionView click can take something like half a second if not more to register on Android ( Pixel 7 so not exactly a slow device ). IOS, Windows, Mac are all fine.

I'm confused by this comment, as clicking should not do anything. It has 1 Java -> C# transition, and allocates a Android.Graphics.Rect. Can you share a .speedscope of this slowdown? https://aka.ms/profile-maui

@KevThompson2020
Copy link

Same issue here. CollectionView click can take something like half a second if not more to register on Android ( Pixel 7 so not exactly a slow device ). IOS, Windows, Mac are all fine.

I'm confused by this comment, as clicking should not do anything. It has 1 Java -> C# transition, and allocates a Android.Graphics.Rect. Can you share a .speedscope of this slowdown? https://aka.ms/profile-maui

I'll run a speed scan when I get change ( probably later this week due to a deadline ). when running in release mode it's a lot better but still feels a little sluggish. in debug mode it takes a good chunk of time to register the click, even to the point of showing the android ripple effect.

@jlinkerlathem
Copy link

I also am experiencing this. I have done a speed scope file of just a simple button click. It loads a screen that has 12 buttons on it. They are not actual buttons, but are custom controls. It takes it about 4 or 5 seconds to load the buttons (removed xaml from the equation and load the buttons via code), then spends another 5 seconds in Microsoft.Maui.Controls!Microsoft.Maui.Controls.Element.SetHandler.

@jonathanpeppers
Copy link
Member

@jlinkerlathem can you share the file?

@jlinkerlathem
Copy link

jlinkerlathem commented Oct 31, 2024

@jonathanpeppers Sure, this one i removed 9 of the buttons. So, I tap a button, it loads a page with three buttons. It reduced the rendering of the page to 2 or 3 seconds, but the SetHandler code still high. But even reduced, three buttons shouldn't take 3 seconds to render (not saying I am not doing something stupid, but, this code worked fine in Xamarin)dotnet-dsrouter.exe_20241031_125557.speedscope.json

Forgot to mention, in the speed scope file, the thread in question is the 24th one, -1465793228

@jonathanpeppers
Copy link
Member

To be clear, we aren't saying button clicks are slow. We are saying navigation to new screens are slow?

In your app, there are a few things that you could improve:

  • CB.Logic!CB.Logic.ViewModels.BaseViewModel.UpdateNetworkConnectivityStatus() looks expensive, does every one of your ViewModels call it? Could that be a one time thing at startup?
  • CB.Maui.Common!CB.Maui.Common.Controls.LathemButton.InitializeComponent() looks expensive, is the XAML complicated? Or are there a lot of them? The XAML does look compiled, are there any warnings related to x:DataType on the bindings?
  • MR.Gestures.dll seems a bit expensive, in general. Can some of the built-in gestures be used instead?

There is a lot of interesting things in here, in general, though. Thanks!

@jlinkerlathem
Copy link

@jonathanpeppers

Yes, it is the navigation I am referring to.

  • UpdateNetworkConnectivityStatus() - I can disable this for testing. We have icons at the top of each screen that indicate the current connectivity status. All it does is use Microsoft.Maui.Networking.Connectivity.NetworkAcess to check if connected, and Microsoft.Maui.Networking.Connectivity.ConnectionProfiles to determine if WiFi, then sets an icon to ImageSource.FromFile based on the results.
  • CB.Maui.Common!CB.Maui.Common.Controls.LathemButton.InitializeComponent() - This was what I honed in on. I tried to remove xaml as the culprit so for the screen i was testing with I switched to a LathemSoundButton that is the same thing but instead of xaml it builds the UI in code (just a grid with the buttons in it). Do you see any issues with the LathemSoundButton? I haven't figured out how to search in SpeedScope, so I need to find where it is still using the LathemButton and switch them all to the Sound one.
  • MR.Gestures.dll - We are actually in the process of removing this, I will go ahead and do this to see what affect it has

Glad you see interesting things. If you see anything else useful let me know. I will swap out the remaining LathemButtons for the LathemSound ones, disable the UpdateNetworkConnectivityStatus(), and remove Mr.Gestures and see what affect that has, if I still see the issue I will submit another speed scope file

@jonathanpeppers
Copy link
Member

If you know what method to look for, use the Sandwich view, search box, and then the call stack should show who called it:

Image

@jlinkerlathem
Copy link

jlinkerlathem commented Oct 31, 2024

@jonathanpeppers Well, that would be why I couldn't figure out how to search, mine does not have a search icon there...

Image

And now I see that the normal ctrl+f instead of bringing up Chrome's Search box, adds a search box to speed scope insert face palm here

@jlinkerlathem
Copy link

@jonathanpeppers Ok, I removed Mr. Gestures. Also removed the UpdateNetworkConnectivityStatus() call. I also moved all of the custom controls involved out of XAML and to be created in C#. I thought it had sped it up one of the times I ran it, but I must have done something wrong as I am still getting slow times. I have attached the latest Speed Scope file. It seems to me the LathemSoundButton is the issue. But I cannot figure out why. As mentioned, I am building it in code.

Its a Border, with a RoundRectangle (with two data triggers), then a Grid (with a TapGestureRecognizer (handles the bound command), and a TouchBehavior (handles swapping the image source to a "pressed" state image if an image has been added) attached), and then an Image and a Label in the grid (each with some bindings). I could see the button being too bulky being the the issue if the problem was worse with more buttons, but it seems even one button on the screen kills it. Any more thoughts?

dotnet-dsrouter.exe_20241101_132904.speedscope.json

@jonathanpeppers
Copy link
Member

If LathemSoundButton is created completely in code, maybe you can get rid of all Binding and DataTrigger?

I have an example here, but maybe the control can override OnBindingContextChanged() and just set the values without bindings?

In this example, a new Organism (imagine it's a model or viewmodel) would come in, set some properties. For changes within a single Organism, I made the Organism fire a single PropertyChanged with an empty string to update. I don't know what your button does, but I bet this would help quite a bit.

Reviewing your logs, I also see how fixing this would help:

So, I'm looking into it.

@jlinkerlathem
Copy link

@jonathanpeppers Hmmm, that could work with this particular control as I do not think the values change after initialization. I guess what confuses me though is what is so different between Maui's handling of this (bindings, xaml creation/parsing, whatever else is involved here) that would make it take so vastly different an amount of time as it did from Xamarin?

I will try the without binding option, but I am worried it will have a negligible affect. Will let you know what I find. I will be starting on testing a release of our software on Monday, so if I have not responded by then it may be a few days before I can circle back.

@jlinkerlathem
Copy link

@jonathanpeppers Also, before I forget, I want to express my genuine appreciation for your persistent assistance in tracking this down

@jlinkerlathem
Copy link

@jonathanpeppers I don't think it is the bindings. Just to see I removed all of the bindings, DataTriggers, Behaviors, the only thing I left was the TapGestureRecognizer to be able to tap on a button and navigate, and the Text Property. I removed EVERYTHING else, and it still takes the same amount of time... I am running out of ideas as everything I have tried has had no affect on it. Like, not even a little. I would at least expect these changes to be speeding it up a little here and a little there. It takes it about 10 seconds from the time I tap the button until the next page loads, and that time has remained consistent through every change I have made....

@jlinkerlathem
Copy link

I switched LathemSoundButton to be just a normal button instead of a content view. Loses my functionality but for testing purposes helps narrow something down. It did speed it up a little. UI creation went from about 3 or so seconds down to 2.25, but there is still a 4 second section of it doing the LayoutHandlers. I will say with the Button instead of Content View, it does load fast the second time you call the page (about 6.5 seconds as opposed to 8, where as with the Content View button it did not speed up after the first time). I think I have stared at this too long now though...

@jonathanpeppers
Copy link
Member

@jlinkerlathem how many controls are on the page you are testing? Is it in the hundreds? (The joke is you should have less views than pixels on the screen)

Also keep in mind the numbers you see in dotnet-trace / .speedscope can be as much as 2x larger than real life with all the instrumentation turned off.

@jlinkerlathem
Copy link

@jonathanpeppers Visually there are less than 20 items on the screen, 12 buttons, a text box, a title bar with a label and a back button, and then a status bar at the top with the time. There may be a few more objects as containers for those objects, but its not a list or anything like that. Just a grid.

I have ran it in release mode to verify the instrumentation was not the culprit and it still takes the same amount of time to laod the page.

As I mentioned, for the next few days I will be on release testing another app, once that is complete I am going to flatten the UI for this page and see what that does. Currently its a ContentPage that is loaded into a BaseContentPage (has the title bar and status bar that is shared by all of the pages), then it loads a Custom Control (a NumberPad) which has 12 of the LathemSoundButtons on it. I am going to flatten that so there is no base page, just all of the stuff on one page, and the number pad code will reside in the parent page and the buttons will be copied on the page and see if that speeds it up. If it does then I will separate things back out one at a time until I hit the issue, and go from there. I will try to update when I get to that point to help others, or if it doesn't solve it when I flatten it I will post another speed scope file.

@KevThompson2020
Copy link

Same issue here. CollectionView click can take something like half a second if not more to register on Android ( Pixel 7 so not exactly a slow device ). IOS, Windows, Mac are all fine.

I'm confused by this comment, as clicking should not do anything. It has 1 Java -> C# transition, and allocates a Android.Graphics.Rect. Can you share a .speedscope of this slowdown? https://aka.ms/profile-maui

I'll run a speed scan when I get change ( probably later this week due to a deadline ). when running in release mode it's a lot better but still feels a little sluggish. in debug mode it takes a good chunk of time to register the click, even to the point of showing the android ripple effect.

I have tried running a speed test this afternoon and its having some issues running.

when I run dotnet-trace collect -p 21001 --format speedscope it crashes.

No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name Keywords Level Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000F00000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile

[ERROR] System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.Stream.ReadAtLeastCore(Span1 buffer, Int32 minimumBytes, Boolean throwOnEndOfStream) at System.IO.BinaryReader.InternalRead(Int32 numBytes) at System.IO.BinaryReader.ReadUInt16() at Microsoft.Diagnostics.NETCore.Client.IpcHeader.Parse(BinaryReader reader) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcHeader.cs:line 55 at Microsoft.Diagnostics.NETCore.Client.IpcMessage.Parse(Stream stream) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcMessage.cs:line 117 at Microsoft.Diagnostics.NETCore.Client.IpcClient.Read(Stream stream) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcClient.cs:line 107 at Microsoft.Diagnostics.NETCore.Client.IpcClient.SendMessageGetContinuation(IpcEndpoint endpoint, IpcMessage message) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcClient.cs:line 44 at Microsoft.Diagnostics.NETCore.Client.EventPipeSession.Start(IpcEndpoint endpoint, EventPipeSessionConfiguration config) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs:line 45 at Microsoft.Diagnostics.NETCore.Client.DiagnosticsClient.StartEventPipeSession(EventPipeSessionConfiguration config) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs:line 101 at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration, String clrevents, String clreventlevel, String name, String diagnosticPort, Boolean showchildio, Boolean resumeRuntime, String stoppingEventProviderName, String stoppingEventEventName, String stoppingEventPayloadFilter, Nullable1 rundown) in /_/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs:line 286

I'll try again tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions delighter legacy-area-perf Startup / Runtime performance migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.)
Projects
None yet
Development

No branches or pull requests