csharpfritz / csharpfritz/MauiWorkshop
Collection Binding Improvement
- Dominant language
- C#
- Stars
- 47
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/csharpfritz/MauiWorkshop/blob/155283ecb14e12968cb677252514aead83b863b7/src/MyNewsReader/ViewModels/NewsFeedListViewModel.cs#L52
Every call to add causes the UI to redraw. This is one of the most common performance hits I see with customer apps using MAUI/XF. ObservableCollections are really meant for "data in motion" (ie. Bluetooth Scan, as data comes in, it pushes on to the list). The bigger the payload of data becomes, the slower the call becomes.
In this case, you are pulling data from a service and pushing onto the observablecollection. My suggestion, since this data is not in motion, is to simply make [ObservableProperty] IList newsFeeds; and push the await right on to that. Less code, no perf hit.
Happy to submit a PR for this one, but I thought you may want to verify this for yourself.
Contributor guide
No contributing guide indexed for this repository
Research direction
Open src/MyNewsReader/ViewModels/NewsFeedListViewModel.cs at line 52 and inspect how data from the service is added to the ObservableCollection. Replace the per-item collection updates with an IList assignment as described, then verify the news feed still loads and displays correctly without repeated redraws.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- mobile-dev, performance
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100