Skip to content

CollectionView is slow to initialize with complex ItemTemplate #22956

Open

Description

Description

Navigating to a page with a CollectionView that uses a complex ItemTemplate freezes the UI for more than 1 sec while the view initializes.

This has been tested in the emulator (where it is not that slow, the view completes in around 300ms), on a Nokia G22 phone, and on a Lenovo TB-J616F tablet, all in Release build.

Test app

Screenshot of test app (see reproduction app link) on start up:

Screenshot of the app after clicking the button:

Profiling

I did some profiling on an actual device. Here's a trace obtained from the repro-app running in Release build on a Nokia G22 phone:
collectionview-trace

It seems the bulk of time is spent in ContentViewGroup.OnMeasure (and related methods). The trace shows time divided among the ~16 items that fits in the screen.

Related issues

Some related issues are:

Steps to Reproduce

  1. Create a new MAUI application from standard template with a Shell
  2. Add a new ContentPage and a button that navigates to the ContentPage
  3. Add a CollectionView with a complex ItemTemplate (e.g., 6+ labels in a Grid using OneWay bindings)
  4. Populate the view with a list of items with random generated data

Link to public reproduction project repository

https://github.com/mikkelrj/MauiApp3/

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android

Did you find any workaround?

Some half-assed workarounds include initializing the view first with a simple template and then when the view has loaded (e.g., in the OnAppeared method) setting the complex template.

The issue remains, though, that the UI will block while the CollectionView is initialized.

Relevant log output

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewplatform/android 🤖s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't workingt/perfThe issue affects performance (runtime speed, memory usage, startup time, etc.)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions