-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Android][CollectionView]MAUI is too much slower than XAMARIN #18531
Comments
https://github.com/BaY1251/MauiDebug/blob/main/Slow/Slow/Model.cs#L24-L35 "Refresh" is called on the UI Thread. You're clearing an ObservableCollection and populating it with 10,000 items. Every time an item is added, a call is tossed to the view to update the UI. This loop is blocking the UI from rendering, since it needs to go through all 10,000 items, while also causing the loop performance to degrade. While what you showed is "slower" between Xamarin.Forms and MAUI, I'm not sure the framework is making that much of a difference here based on how you wrote your app. Case in point: public ObservableCollection<Item> ItemList { get; set; } = new();
public void Refresh()
{
var tick = Environment.TickCount;
var testList = new List<Item>();
for(int i = 0; i < 10000; i++)
{
testList.Add(new Item());
}
// All items are loaded at once in the observable collection.
ItemList = new ObservableCollection<Item>(testList);
Time = Environment.TickCount - tick;
OnPropertyChanged(nameof(Time));
OnPropertyChanged(nameof(ItemList));
} Changing it so the observable collection is set in one go "improves" the tick score to around 40 to 100 in Xamarin.Forms and MAUI. You could probably "improve" it more by having the list recreation be done on a background thread and then update the ObservableCollection only when the data changes in bulk. |
@drasticactions Thank you for your suggestion. It's very good and there has been a significant improvement But even after the changes, Xamarin still performs better, doesn't it? |
It depends on what you're testing. Your example, in my opinion, isn't testing the performance of CollectionView but of how fast the ObservableCollection loop completed. With each item you add to the ObservableCollection, a call is made to the CollectionView UI to add a new row. Since this is happening on the UI Thread, your app stops, renders the UI, then continues. Eventually, you add enough rows so that Virtualization kicks in and the UI stops being rendered until it is shown (At which point, no new UI is created, so the rest of the loop completes faster). So with a better benchmark, it could be that the exact rendering of one row is "slower" in MAUI than in Xamarin.Forms, but that too isn't complete. If you look at what I wrote and run it in both Xamarin.Forms and MAUI with your sample, with your ticks metrics, the rendering of the UI it's about the same values for both. Because rendering every row at once are more or less similar. @jonathanpeppers are there other tips that could help here? The only other thing I know (since you've shared this UI several times for different bugs) is that the layout is quite intensive, and seeing it in both Xamarin.Forms and MAUI, the scrolling performance is poor in both. But I'm not sure if it's a platform issue, or if your UI is not well optimized, or both. |
Yes, I am writing an application that displays a large amount of data. After modifying according to your suggestion, refreshing the data is indeed much faster, but MAUI will noticeably lag for a while before the data is fully displayed. Therefore, I believe XAMARIN performs better in this area.But how long does it take for the data to fully display? I cannot write corresponding code to compare the two. In addition, after changing the code of #18441, it is confirmed that a crash still occurred, possibly due to a memory leak. Even if the data volume is small, as long as the CollectionView is frequently refreshed, it will still crash, which I am helpless about! |
Duplicate of #18505 |
@BaY1251 just to verify, are you comparing If not, you are comparing Mono/Xamarin's JIT vs .NET 7's Interpreter, as It's best to use |
@jonathanpeppers I Build in Release . Even make a apk, Install all my possible Android Devices, TO Compare Them |
@PureWeen Please confirm that this issue is not related to CollectionVIew scrolling performance Or are the underlying issues the same for both? |
After #18505 is addressed if you're still having issues then can you create a new issue? |
@PureWeen I have noticed that CreateContent() of datatemplate is much slower than in XF, may be here is the problem. because the same template in XF takes 30 ms to create and 200 ms in MAUI. |
Description
I created two almost identical projects using MAUI and XAMARIN.
Keep the default configuration (
Release
build, MAUI enabled AOT, XAMARIN not enabled AOT.)MAUI took almost twice the time
Steps to Reproduce
XAMARIN
Download https://github.com/BaY1251/MauiDebug.git
Open /Slow/Fast/Fast.sln to compile and generate a project
Run & press 'REFRESH'button
MAUI
Download https://github.com/BaY1251/MauiDebug.git
Open /Slow/Slow/Slow.sln to compile and generate a project
Run & press 'REFRESH'button
Link to public reproduction project repository
https://github.com/BaY1251/MauiDebug.git
Version with bug
8.0.0-rc.2.9511
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
Android7.1 Android11.0 ... Mobile phones and tablets ...
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: