[iOS] UI Frozen When Adding Many Children To a Layout
#3,417 opened on Jul 27, 2018
Repository metrics
- Stars
- (5,644 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Description
To best describe this issue the repro project has the main page split in two:
1. On the left I create a StackView to which I add 1000 simple labels, programatically, at the press of the "FORMS" button. While the content is rendered the UI is completely frozen for many seconds, depending on the number of children. The rendering time increases exponentially, 200 children will not take twice as long as 100 children, but much more, reaching 35 seconds for 1000 labels on an iPhone X Simulator (iOS 11.4)
- setting the children in XAML leads to the same poor performance
- surprisingly, the Android version is smoother, though it's still slower than the native approach
2. On the right, at the press of "NATIVE" button I add a ContentView for which I have created some crude renderers (iOS and Android), enough to be able to add the same 1000 labels to the view from the native projects. The difference is huge, as illustrated by the screenshot.

EnsureChildrenOrder, BringSubviewToFront seem to be the bottleneck.
I have found some good discussions on the Forums about this, but no solution/workaround was found:
- https://forums.xamarin.com/discussion/57185/performance-bottleneck-on-android-in-children-add
- https://forums.xamarin.com/discussion/70719/ensurechildorder-in-xamarin-forms-platform-ios-very-slow-when-appending-child-controls
- https://forums.xamarin.com/discussion/71492/major-performance-issues-with-dynamic-layout-changes
- https://forums.xamarin.com/discussion/43869/keeping-ui-thread-from-freezing-when-setting-large-content
Expected Behavior
The UI shouldn't be frozen for so long, on 200 elements the usability is already reduced. A ListView is not always feasible to use, I'm thinking about an usecase where I would want to display a Data Grid to the users, set in a ScrollView with Orientation set to Both
Basic Information
- Version with issue: 3.1.0.637273
- Last known good version: -
- IDE:
- Platform Target Frameworks:
- iOS: 11.4
- Android: 8.1
- Affected Devices: tried it on iPad Air 2, iPhone 5s, various simulators (including iPhone X) and Huawei Nexus 6P (API 27)