maui: CollectionView with many items (10,000+) hangs or crashes on iOS

Description

A simple CollectionView with a lot of items (100,000 or so) will hang on Windows and iOS. Memory consumption goes through the roof (gigabytes of allocations) and will eventually even crash on iOS. On Android this seems to work without any issues.

It’s extremely easy to reproduce. Simply create a blank application and add this CollectionView to the page:

<CollectionView x:Name="listview"/>

Bind 100,000 strings to the collection view and watch it hang on startup. Running in a debugger shows the memory usage going up to gigabytes.

Steps to Reproduce

  1. Create a new MAUI app
  2. Add a CollectionView to the main page with or without an ItemTemplate
  3. Bind 100,000 strings to the CollectionView
  4. Run

Link to public reproduction project repository

https://github.com/activa/Maui8CollectionViewBug

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 24 (20 by maintainers)

Most upvoted comments

@PureWeen @jsuarezruiz @davidortinau

Can this issue please be prioritized, together with #18639? There is no workaround possible and it’s a true showstopper. Any app that tries to show more than a few thousand items in a CollectionView is simply unusable or will crash.

I can understand that cosmetic issues are being deferred to the backlog but anything as fundamental as this should get the attention it deserves.

I’m getting very frustrated by the lack of sense of urgency to fix major bugs in MAUI, and I’m definitely not the only one. The first “stable” version was released 18 months ago and it has never been stable enough to be used in a real world application. The number of regressions being introduced with every release is also quite alarming.

I figured out what’s going on, but I don’t think it’s going to be an easy fix

In ItemsViewController.GetSize(), the content size of the collection view is calculated by calling CollectionView.CollectionViewLayout.CollectionViewContentSize. What that does is call GetSizeForItem() on every single item (this is done by UIKit, not MAUI code). When there are a lot of items, this will take quite a bit of time (on my iPhone test device, this takes 30 seconds for 200,000 items). To make matters worse, the content size is AGAIN calculated in ItemsViewController.InvalidateMeasureIfContentSizeChanged() , which again takes 30 seconds.

The thing is, there’s really no good reason to want to calculate the content size of a collection view. I’m trying to understand why this is needed.

Tried with 8.0.4-nightly.9679 and there’s no change. It still crashes with the test project I linked to this issue.