SwiftUI and AnyView: Performance benchmarks

I think that maybe under the hood, SwiftUI is generating calls to UITableViewDataSource.tableView(_:numberOfRowsInSection:) (or something functionally similar), and that that is inefficient for AnyViews, since there is no 1-1 correlation between a AnyView and a table view row. However, for statically known SwiftUI.TupleView, VStack and others it can infer the number of rows per ForEach "row".

On the other hand, for _ConditionalContent, AnyView and other similar views, it has to walk the entire collection in order to calculate the number of rows.

1 Like