How does SwiftUI decide what to redraw? What are identity and diffing?
The gist
SwiftUI does not store your structs; it stores an attribute graph — a tree of nodes with state and dependencies. When a dependency changes (@State, a property read from an @Observable model, @Environment), only the dependent nodes are marked, their body is re-evaluated, the new tree is compared with the old one (diffing), and only the real changes are pushed to UIKit/Core Animation. To match old and new nodes the framework needs identity.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep