xamarin/Xamarin.Forms

Bad performance on UWP ListView if ItemsSource is not an ObservableCollection

Open

#4,059 opened on Oct 11, 2018

 (3 comments) (0 reactions) (0 assignees)C# (1,926 forks)batch import
a/listviewa/performancee/3 :clock3:help wantedin-progressinactivep/UWPup-for-grabs

Repository metrics

Stars
 (5,644 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Description

In my application, I have a ListView with an ItemsSource that implements IEnumerable, IList, ICollection and INotifyCollectionChanged (it is a custom collection). By default, my list contains only null elements, but on the first access to an element, it is loaded asynchronously (from an sqlite database) and I use INotifyCollectionChanged to notify the load once it has been done. It works fine on Android and only items displayed on the screen are loaded. It worked well on UWP with Xamarin Forms 2.5. With Xamarin Forms 3, on UWP, since my list is not an ObservableCollection, the ListViewRenderer creates its own ObservableCollection and accesses all the elements of my source list to copy them causing asynchronous loading and a big performance problem.

Steps to Reproduce

  1. Create a custom collection that implement IEnumerable, IList, ICollection and INotifyCollectionChanged.
  2. Create a collection of this type with 1000 items.
  3. Use it as ListView ItemsSource on a page and run the project on UWP

Expected Behavior

The ListView should only access visible items (or a little more) and it should not copy the list because it implements all necessary interfaces.

Actual Behavior

The ListView reads the entire collection.

Basic Information

  • Version with issue: 3.2.0.839982
  • Last known good version: 2.5
  • IDE: Visual Studio 2017
  • Platform Target Frameworks:
    • UWP

Contributor guide