Replies: 7 comments 6 replies
-
Can you convert it into an issue than discussion? This is something MAUI team should work on. |
Beta Was this translation helpful? Give feedback.
-
If you really want to solve it, write your own design completely. Perhaps this is not for everyone, but what do you need for a "collection view"?
EDIT: On further assessment, my custom "collection view" is showing the same problems. Doing this won't fix it. This is likely a deeper Maui problem as noted here |
Beta Was this translation helpful? Give feedback.
-
There are some other CV. I use the Sharpnado CV. But still with Xamarin Forms. Perhaps scrolling works better with one of this. |
Beta Was this translation helpful? Give feedback.
-
I have also run into this problem with CollectionView, my solution was also to avoid writing complex datatemplates and to use more native android controls usually based around ConstraintLayout. I didn't get the chance to profile my layouts but performance was massively improved with this change. |
Beta Was this translation helpful? Give feedback.
-
Please test the nightly builds. https://github.com/dotnet/maui/wiki/Nightly-Builds The upcoming service release 4 has some performance fixes, including targeting Android |
Beta Was this translation helpful? Give feedback.
-
Have you tried setting the nursery size to something reasonable? The default in Xamarin was something like 512KB, which is wayyyy too small. Not sure if it's been changed in MAUI. 64-128M seems to be a better spot currently. https://stackoverflow.com/questions/72799143/how-do-i-specify-nursery-size-for-android-in-net-maui-app I'd recommend starting it at 1m and, if it makes a difference, increasing it by a factor of 2 (it has to be a factor of 2...) until the ROI isn't worth it for your app. |
Beta Was this translation helpful? Give feedback.
-
use native controls, see this Android solution, works for me: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The problem: CollectionView seems to be really struggling on Android, especially when you scroll through the items quickly.
Look at the example below. The item template is pretty simple and a very typical setup.
It's just a grid with 3 columns, with a
Label
, aButton
, aPath
, and anEntry
. All of these are enclosed in aSwipeView
. But even with this simple layout, we hit a performance bottleneck pretty quickly. Which is really bad because the real world apps that I had worked on require way more complex layouts than that.Here is what scrolling through such a collection view looks like on a Xiaomi Note 8T (android 10). It's not a new phone by any means, but it's modern-enough to not have hiccoughs with such simple tasks. I use it daily and it's been working well enough for years that I haven't even considered replacing it yet.
Screenrecorder-2023-10-14-15-05-14-655.mp4
Try the fling gesture to scroll through the items and you pretty much get a slideshow. Even trying to go through the list without lifting your finger gives you some small stutters.
What I'm trying to figure out is what is at fault here and how can we as developers work around it or what can the .NET MAUI team do about it and the timeline of it.
I recorded a trace of what was happening during scrolling. I'm not an expert in analyzing this kind of stuff but it obviously doesn't look good.

If I'm not mistaken there's nothing that I do outrageously wrong in my layout nor are the binding slowing everything down (there's a total of 3 bindings in the example without any converters or anything).
In this example, the
OnBindViewHolder
calls take a relatively small amount of time but it scales very aggressively with the amount of bindings and complexity of the layout. With a layout with 3 rows, 3 columns, 8-10 labels, 1 image, and 4 paths it took 250ms. This means if you scroll by4 items
at once you'll get a1s
lag.I obviously understand that with using MAUI comes a performance hit but as developers we can't be expected hit such an issue soooo early. I mean, if you use something hard enough you'll eventually break it but this is nowhere near a heavy or unusual use case.
Here is the project and scope file: https://github.com/Hooterr/AndroidCollectionViewPerformance
Potential solution: GO NATIVE
After digging for hours through recorded scopes and trying to optimize the layout of item templates I found out that the only solution was to write the layout natively. I translated the real-world-complex from XAML to android XML. I setup the RecyclerView to use my layout and bind my collection of items through the adapter. I even used all the value converters that I used in XAML to set texts and colors inside
OnBindViewHolder
as well as the sameIFontManager
as MAUI to load fonts. Then made a barebones handler to render my native recycler view inside my XAML page. The effect was absolutely astonishing. There was nothing I could do to make that list lag or stutter in any way. Even in Debug mode, when the MAUI CollectionView was almost unusable, the native one was just flying.It seems that .NET<->Java interop is not to blame here. You wouldn't be able to tell if this sample list was written directly in Java or Xamarin.Android. What it looks like to me is that the underlaying architecture of MAUI just does so much work underneath that it's just unfeasible to make anything more complex than a list of simple labels.
At this point, what I would recommend to everyone is, if you're having performance issues with CollectionView, just write your layouts natively. It's a shame because you have to do it twice but there seems to be no other choice.
Beta Was this translation helpful? Give feedback.
All reactions