maui: CollectionView slow/jittering scroll
Description
When there is a complex layout Scroll does not work efficiently.
Steps to Reproduce
I have this layout, as you can see I have used the recommended bindings OneTime and CompressedLayout.IsHeadless="True".
ItemSizingStrategy has to be in mode: MeasureAllItems. Each element can have a different height.
There are like 30-40 elements, the Scroll is unacceptable, both in debug/release mode. Thus, the application cannot be released to production.
I don’t know if I can improve my design, but i can’t get it. Any help is welcome.
Link to public reproduction project repository
https://github.com/angelru/CvSlowJittering
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12
Did you find any workaround?
No response
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 11
- Comments: 49 (24 by maintainers)
Commits related to this issue
- [controls] fix memory leak in `BindableLayout` Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering In reviewing the above sample, I found the fol... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [controls] fix memory leak in `BindableLayout` (#13550) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering In reviewing the above sample, I f... — committed to dotnet/maui by jonathanpeppers a year ago
- [controls] fix performance issue in {AppThemeBinding} Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a customer sample app, I noti... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [graphics] fix CA1307 and CA1309 for performance Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering While reviewing the above sample, I saw time... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [graphics] fix CA1307 and CA1309 for performance (#14627) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering While reviewing the above sample, I... — committed to dotnet/maui by jonathanpeppers a year ago
- [controls] fix performance issue in {AppThemeBinding} (#14625) * [controls] fix performance issue in {AppThemeBinding} Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.co... — committed to dotnet/maui by jonathanpeppers a year ago
- [generator] emit faster overloads for non-virtual Formatted props (#1101) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/xamarin/java.interop/issues/994 Context: 7... — committed to xamarin/java.interop by jonathanpeppers a year ago
- [controls] improve performance of {Binding} I wrote a benchmark for `Binding`, such as: [Benchmark] public void BindName() { var binding = new Binding("Name", source: Source); ... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [android] MauiTextView doesn't need ViewAttachedToWindow Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a customer sample, I notic... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [android] MauiTextView doesn't need ViewAttachedToWindow (#14833) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a customer sam... — committed to dotnet/maui by jonathanpeppers a year ago
- [controls] improve performance of {Binding} (#14830) I wrote a benchmark for `Binding`, such as: [Benchmark] public void BindName() { var binding = new Binding("Name", sourc... — committed to dotnet/maui by jonathanpeppers a year ago
- [core] use StringComparer for Dictionary/HashSet Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering When profiling the above customer app while ... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [core] use StringComparer for Dictionary/HashSet (#14900) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering When profiling the above custome... — committed to dotnet/maui by jonathanpeppers a year ago
- [generator] improve *Implementor constructors Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a .NET MAUI customer sample while scr... — committed to xamarin/java.interop by jonathanpeppers a year ago
- [android] reduce interop calls in MauiDrawable Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a .NET MAUI customer sample while sc... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [generator] improve *Implementor constructors (#1105) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a .NET MAUI customer sampl... — committed to xamarin/java.interop by jonathanpeppers a year ago
- [android] reduce interop calls in MauiDrawable (#14933) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Profiling a .NET MAUI customer sam... — committed to dotnet/maui by jonathanpeppers a year ago
- [android] improve layout performance of Label Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Context: https://github.com/jonathanpeppers/lols... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [android] improve layout performance of Label Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Context: https://github.com/jonathanpeppers/lols... — committed to jonathanpeppers/maui by jonathanpeppers a year ago
- [android] improve layout performance of Label (#14980) Context: https://github.com/dotnet/maui/issues/12130 Context: https://github.com/angelru/CvSlowJittering Context: https://github.com/jonathanp... — committed to dotnet/maui by jonathanpeppers a year ago
I believe we have enough changes to close this one, testing the above sample with my script here:
https://github.com/jonathanpeppers/maui-scrolling-performance
.NET 7:
.NET 8
net8.0branch +mainon top:Scrolling feels a lot better. I tested these on a Pixel 5 (released in Oct 2020).
The list of performance changes, I think led to the improvement here:
The recent fixes for memory leaks, likely also helped.
We can always make this even better, but I think this is enough to close this one for now. Thanks!
What do I do if my app still scrolls slowly?
First, try it on the latest .NET 8 release and see if things have improved.
If not, file a new issue with a sample app, and we can profile the app and see what we find. You can also try the instructions at https://aka.ms/profile-maui to profile it yourself.
The memory leak here may have been fixed by: https://github.com/dotnet/maui/pull/13656
No idea about the performance of it, though.
Need to retest this issue, but I’ve been working on this all week instead: https://github.com/dotnet/maui/pull/13833
Fixing a performance issue with
{AppThemeBinding}(https://github.com/dotnet/maui/pull/14625) a decent start to help this one.The next thing that stuck out to me here is something we can fix in Java interop:
It looks like we can improve all
stringproperties in: https://github.com/xamarin/java.interop/pull/1101Following https://aka.ms/profile-maui, I profiled this sample on Android:
https://github.com/angelru/CvSlowJittering
One thing odd is how much time is spent in:
Looking at the stacktrace, all this time is spent doing things with
{AppThemeBinding}:This code seems like it runs on all platforms, so maybe there is a general win here.
If we could avoid 100s (1000s?) of nested views all subscribing to this event through
WeakEventManager– that uses System.Reflection underneath.In a future Visual Studio preview, there will be a .NET 8 Preview optional checkbox. And you can just change your project to
net8.0to try it.In a more distant future, you’ll be able to change
<MauiVersion>to try new versions (even in different projects), but the groundwork for this is only in .NET 8+.This PR also helps this issue: https://github.com/dotnet/maui/pull/14701
The
MapTextColormethod used to callTextView.Text(with the same text!):I will profile this app again w/ .NET 8 after all the current changes are there.
Another example of this issue is: https://github.com/IeuanWalker/MauiIssueRepo-7494
This recent change would have some decent impact for scrolling performance on Android: 160e721c05c9ddf795cb7947182a333968862734
Let me retest this one again with latest dotnet/maui/main. I did not get to the point of looking at BindableLayout performance yet.
@jsuarezruiz I already put the repository in the problem description https://github.com/angelru/CvSlowJittering
@angelru Yes, I tested on Samsung Galaxy Tab Active 2 - Android 9. The collection View scroll is laggy, very very slow @jsuarezruiz
@mohachouch With my provided example, were you able to see the lag?
Have you tried changing to a ListView? also try this Sharpnado.CollectionView
the same issue