Michael Long
1 min readMay 17, 2024

--

Enjoyed the article, but I'm afraid some of your conclusions are a bit off.

First thing is that there's a difference between view body evaluation and view rendering. SwiftUI will often reevaluate a view in order to see if a state change has affected the view's elements. If so, a view will be redrawn.

One thing that's throwing off your conclusions is that in some cases the very thing you added to visualize changes is in fact requiring the view to always be rendered. Evaluate a view body with .debugBackground() added and it will always be rendered.

Of course, that assumes that SwiftUI thinks the view needs to be checked in the first pace.

Determining if a subview should update (or be checked for updates) is an intricate dance of diffing new struct values against old struct values and/or evaluating the view body for changes. And as you've noticed that can be simple (POD) or more complex.

Adding Equatable to the view does nothing in the final example and it can be removed. You can improve performance using Equatable but only if you wrap the view in EquatableView/.equatable. You'd think SwiftUI would always check for equatable performance, but it doesn't.

https://swiftwithmajid.com/2020/01/22/optimizing-views-in-swiftui-using-equatableview/

There are several reason why LazyVStack/List/ForEach can have issues requiring evaluation of the entire list. For some see my article on AnyView.

https://medium.com/the-swift-cooperative/swiftui-why-you-need-anyview-99b1c48794a4

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)