maui icon indicating copy to clipboard operation
maui copied to clipboard

[Android] Slow scrolling, laggy performance

Open jsuarezruiz opened this issue 3 years ago • 5 comments

Description

It is a list using CollectionView with elements using Border. It's a list of only 5 items, but there must be something wrong somewhere because it lags considerably.

surfer-droid-scroll

Steps to Reproduce

  1. Download or sync https://github.com/jsuarezruiz/netmaui-surfing-app-challenge
  2. Launch the App on Android and scroll the main page.

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 and 13

Did you find any workaround?

No response

Relevant log output

No response

jsuarezruiz avatar Aug 17 '22 08:08 jsuarezruiz

This bug has been reported so many times, none of them will be fixed

HausBJB avatar Aug 17 '22 18:08 HausBJB

In traces, I can see that the CollectionView calls SurfingApp!SurfingApp.Views.Templates.PostItemTemplate..ctor() again and again. Looks like it recreates the whole view on every scroll.

Attaching traces. They contain everything that happens during the swipe gesture: maui-app-trace.speedscope.json.zip

byme8 avatar Aug 17 '22 19:08 byme8

In traces, I can see that the CollectionView calls SurfingApp!SurfingApp.Views.Templates.PostItemTemplate..ctor() again and again. Looks like it recreates the whole view on every scroll.

Attaching traces. They contain everything that happens during the swipe gesture: maui-app-trace.speedscope.json.zip

Reviewed and can see the same. PostItemTemplate is created again and again.

jsuarezruiz avatar Aug 22 '22 10:08 jsuarezruiz

Related: https://github.com/xamarin/Xamarin.Forms/issues/8718#issuecomment-767615301

jedusei avatar Aug 24 '22 15:08 jedusei

I have the same problem. How do you upload such an app to the Play Store? you will be laughed at immediately. certain things need to be fixed as a matter of priority.

HausBJB avatar Sep 15 '22 18:09 HausBJB

Hey guys, I've developed a workaround to this issue that you can use until the MAUI team provides an official fix. Please try it out and let me know whether it works for you too.

https://gist.github.com/jedusei/e15f45e1ae385d8b57413c168d3ef730

jedusei avatar Sep 30 '22 12:09 jedusei

Hello when can I expect this fix for net 6?

HausBJB avatar Oct 20 '22 19:10 HausBJB

THIS IS WHAT I recognized IN ALMOST ALL .NET NATIVE CONTROLS if LOTS of XAML Markups (FASTER ON RELEASE MODE)... Yes it is real native, But this undergo lots of compilations, logics and codes before it landed to native view. But it is getting better now.

nextcodelab avatar Nov 29 '22 06:11 nextcodelab

Hola chicos, he desarrollado una solución para este problema que pueden usar hasta que el equipo de MAUI proporcione una solución oficial. Por favor, pruébalo y hazme saber si funciona para ti también.

https://gist.github.com/jedusei/e15f45e1ae385d8b57413c168d3ef730

This should improve scrolling with collectionview?

angelru avatar Mar 16 '23 08:03 angelru

Reviewing this app, the first thing I noticed that the PostItemTemplate.xaml has about 100 lines of styles inside. I moved this into the main Styles.xaml, so it isn't created for every row.

Next, I recording a .speedscope while scrolling (tested the net8.0 branch): surfer.zip

35% of the time is spent in:

image

This is deeply nested doing interop from C# -> Java -> C# -> Java many levels deep.

I think we should remove this C# method somehow:

https://github.com/dotnet/maui/blob/3859318f971b39b9d4a0e48492a3daed012cb695/src/Core/src/Platform/Android/WrapperView.cs#L93-L114

And put everything in Java, so nothing does interop at all here. I will investigate if it's even possible, because there may be a lot of C# logic happening here.

jonathanpeppers avatar Mar 24 '23 19:03 jonathanpeppers