Skip to content

Profiling With Instruments (SwiftUI)

A SwiftUI guide for coding agents. Also covers instruments swiftui template, view body duration, slow body property, time profiler ios, frame drop debugging, performance profiling xcode.

The SwiftUI template in Instruments shows how often view bodies run and how long they take, which is the data you need when scrolling stutters or updates lag. Profile on a schedule, not only when something breaks; small regressions are easiest to catch one change at a time.

Starting a Session

Build in profiling mode with Product > Profile (Cmd+I), pick the SwiftUI template, and record. Profile on a real device only; the simulator's performance tells you nothing about the phone.

View Body

SwiftUI calls body whenever a view's dependencies change (state, observed objects), diffs the result, and commits a Core Animation transaction. Watch the Average Duration column:

  • The whole update must fit a 16 ms frame, and 8 ms on ProMotion displays, or the user sees a glitch.
  • Keep body cheap. Never allocate heavy objects such as DateFormatter inside body; it runs on every dependency change.

View Properties

This section lists every changed view property. Property updates outnumber body calls, because SwiftUI merges several property changes into one body run. Scan it for properties that update more often than you expect; each one is a diffing trigger you may not need.

Time Profiler

The Time Profiler section times every function. The heaviest stack trace on the right is usually the answer; use the Call Tree filter at the bottom to hide system libraries so your own code surfaces.

Use this guidance in your coding agent

Install the Better Design MCP once. Your agent then loads this page with one call.

get-swiftui-guide({ topic: "swiftui-profiling-swiftui-app-using-instruments" })
claude mcp add --scope user better-design --transport http https://better-design.com/api/mcp --header "Authorization: Bearer <YOUR_API_KEY>"
Browse related design systems