The problem with profiling by feel
A SwiftUI screen stutters when you scroll, or a button takes half a second to respond. You open Instruments, record 40 seconds of tapping around, and end up with a call tree full of system frames and no idea which part of the trace matters. The fix is to make profiling repeatable. Profile the same build type every time, mark the interaction you care about in code, pick the instrument that matches the symptom, and compare runs instead of reading one trace in isolation.
Set up a trace you can trust
Release build, real device
Product > Profile (Command-I) builds with the Release configuration by default and launches Instruments. Keep it that way. Debug builds skip optimisations, so a function that looks slow in Debug may be fine once the optimiser runs. Donny Wals makes this point in his Instruments guide and adds that he doesn’t spend time on issues that only show up in Debug. Antoine van der Lee’s profile, fix, verify article agrees that a physical device gives more realistic numbers than the simulator, which runs on your Mac’s much faster CPU. Use the oldest supported device you have, because that’s where your users feel hitches first.
One version requirement: the SwiftUI instrument introduced in Instruments 26 needs Xcode 26 and a device running an OS release that supports recording SwiftUI traces, according to Apple’s WWDC25 session on SwiftUI performance. Instruments 27 also drops older targets, and the Xcode 27 release notes list iOS 17 as the minimum device version it can profile.
Mark the interaction with a signpost
A trace covers everything the app did while recording. A signpost interval lets you cut it down to the part you care about. OSSignposter (iOS 15+) records intervals that show up in the Points of Interest track when you use the pointsOfInterest category.
import os
enum Signposts {
static let feed = OSSignposter(subsystem: "com.example.reader", category: .pointsOfInterest)
}
@MainActor
func refreshFeed(_ feed: FeedModel) async {
let id = Signposts.feed.makeSignpostID()
let state = Signposts.feed.beginInterval("Refresh feed", id: id)
defer { Signposts.feed.endInterval("Refresh feed", state) }
await feed.reload()
}
FeedModel stands in for your own type. For a moment without a duration, such as a tap, call emitEvent(_:id:). Keep the signposts in the codebase after the investigation. Every future profiling session can reuse them, and MetricKit can aggregate signpost intervals from production devices through its own log handle.
In Instruments, right-click the interval in the Points of Interest track and set it as the inspection range. Every other track then shows only what happened during that interval.
Pick the instrument by symptom
Writers disagree a little on where to start. Donny Wals recommends the SwiftUI template for any SwiftUI app, even when you’re not chasing a SwiftUI-specific problem. Apple’s WWDC26 responsiveness session starts a hang investigation from the Swift Concurrency template, which includes Time Profiler. Van der Lee picks Time Profiler for a busy CPU and System Trace for a frozen UI with an idle CPU. These choices fit together. Use the SwiftUI template when the symptom is in the UI, such as slow scrolling, a laggy transition, or views updating too often. Use the Swift Concurrency template or System Trace when the main thread is stuck and you don’t yet know why.
SwiftUI instrument: long and unnecessary updates
The SwiftUI template records the SwiftUI instrument alongside Time Profiler and the Hangs and Hitches instruments. Apple’s SwiftUI performance article describes the lanes:
- Update Groups shows when SwiftUI is doing work at all. If CPU spikes while this lane is empty, the problem is outside SwiftUI.
- Long View Body Updates marks
bodyevaluations over 500 microseconds in orange and over 1,000 microseconds in red. - Long Platform View Updates covers UIKit and AppKit views hosted in SwiftUI.
- Other Long Updates covers geometry and text layout work.
Start with red. Control-click a long update and choose Set Inspection Range and Zoom, then look at the Time Profiler track for that range to see which code ran. A single long update might not contain enough samples to be conclusive, so repeat the interaction several times while recording, then use Show Calls Made by your view’s body in the call tree to merge all instances.
The usual cause is work in body that belongs elsewhere. The WWDC25 demo found a list row creating formatters and computing distance strings on every update. Formatters, sorting, filtering and date maths belong in the model, computed when the input changes and read as stored values by the view.
The second kind of problem is updates that shouldn’t happen at all. Each one is short, but a long Update Groups bar with no long updates inside it means many cheap updates adding up. Hover over an update, choose Show Causes, and Instruments draws the Cause & Effect Graph: blue nodes are your code, gray nodes are the system, and edges show which state change or environment write made which view body run. Donny Wals’ test question applies here. For each update, ask whether you expected that body to run.
The fixes Apple lists:
- Read narrower state. A view that reads a whole collection to answer one question about one item depends on the entire collection. In the WWDC25 example, each row read a favourites array, so adding one favourite re-ran every row. Giving each row its own small
@Observablevalue fixed it. - Keep fast-changing values out of the environment. Every view that reads the environment is checked when any environment value changes. Geometry values and timers don’t belong there.
- Don’t store closures that capture
self. A stored closure that captures view properties makes SwiftUI recompute it whenever any of those properties change. Call a content-building closure in the initializer and store its result. - Migrate from
ObservableObjectto@Observable. Observation tracks the properties a view actually reads.
The graph shows only one changing property per edge. After a fix, record again: the same view may still update for a second reason you couldn’t see before.
Instruments 27 adds two things here, according to the release notes. The SwiftUI instrument records more detail about layout passes and why a layout computation wasn’t cached, and the View Hierarchy detail gains a Summary of Updates focus action that shows what a given view in the hierarchy is updating.
Time Profiler: what the CPU is doing
Time Profiler samples call stacks, so it shows code that was running and nothing about code that was waiting. Van der Lee’s settings are the standard ones: separate by thread, invert the call tree so the heaviest leaf functions sit at the top, and hide system libraries so your own frames stand out. Then sort by weight and start at the top.
Instruments 27 adds a Top Functions mode, which merges every occurrence of a function across all call paths and ranks them by self weight. The WWDC26 session uses it to find overhead that was spread thinly across many callers, which a normal call tree hides because no single branch looks heavy. Use the call tree to understand a path and Top Functions to find death by a thousand cuts.
Hangs: when the main thread stops responding
Apple’s hangs article defines a hang as a busy main run loop that delays a discrete interaction. Most of Apple’s tools report one when the main run loop is unresponsive for more than 250 ms, and the Hangs instrument lets you lower that threshold. A delay under 100 ms is rarely noticeable, so a 100 ms threshold during development catches problems before users see them.
The WWDC26 session splits every hang in two. Check main-thread CPU usage during the hang:
- High CPU means the main thread is busy. Use Time Profiler and Top Functions, then make the work cheaper or move it off the main actor. In Swift 6.2 and later, an
@concurrentasync function runs on the concurrent pool instead of the caller’s actor. - Low CPU means the main thread is blocked, waiting on file I/O, a lock or another process. Time Profiler shows nothing useful because nothing is running. Use System Trace, which in Instruments 27 combines system calls, VM faults and thread states into one plot, and the new inspector panel, which shows details such as the size of a write.
The Swift Executors instrument, new in Instruments 27, shows tracks for the main actor, the cooperative pool and custom executors. It reveals the case where nothing on the main actor is slow by itself, but too many unrelated tasks queue up behind each other there. Executor names are shown properly when profiling iOS 27 and later.
Allocations: memory that keeps growing
Use the Allocations instrument when memory climbs as you navigate. The reliable technique is generations. Start a recording, bring the app to a steady state, then press Mark Generation. Open and close the suspect screen several times, marking a generation after each round. Objects that persist in every generation after the screen has closed are your leak or abandoned memory. Sort by persistent bytes and look for your own types first. For retain cycles, the Memory Graph debugger in Xcode is faster at showing who holds a reference, so the two tools work as a pair.
Image decoding is a frequent cause of memory spikes in scrolling screens. A large image decoded at full resolution to fill a small thumbnail shows up as a big allocation for every row that scrolls into view.
Verify with Run Comparisons
A fix isn’t done until a second trace shows it. Instruments 27 adds Run Comparisons, covered in both the WWDC26 session and van der Lee’s article:
- Record a baseline run with your signpost in place.
- Make one change and record the same interaction again.
- Filter both runs to the same signpost interval.
- Select the main thread track, press the compare button and pick the baseline.
Instruments matches functions between the runs and shows the difference, regressions in red and improvements in green. A fix often introduces new functions, which appear as regressions, so check that the total moved the right way. Comparisons are saved in the trace document, so you can attach the file to a pull request.
Traps
- Profiling the simulator. It runs on Mac hardware. Timings mean little, and some instruments behave differently.
- Recording too long. A trace of the whole session mixes several interactions. Record one flow, or use a signpost range.
- Trusting one sample. A single long update may be noise. Repeat the action and look for the pattern.
- Fixing the first red bar in the timeline. Fix the update the user feels, during the interaction you marked.
- Forgetting the second cause. The Cause & Effect Graph shows one property per edge, so re-record after each fix.
Workflow checklist
| Step | Tool | Done when |
|---|---|---|
| Build | Product > Profile, Release, physical device | Trace recorded on the oldest device you support |
| Mark | OSSignposter interval, pointsOfInterest |
Interval visible in Points of Interest |
| UI updates | SwiftUI instrument, Cause & Effect Graph | No red body updates, every update expected |
| CPU | Time Profiler, Top Functions | Heaviest own function understood |
| Hangs | Hangs, System Trace, Swift Executors | Busy or blocked cause identified |
| Memory | Allocations with generations, Memory Graph | No persistent growth after closing a screen |
| Verify | Run Comparisons on the same signpost | Main thread time lower than the baseline |
Sources and further reading
- Understanding and improving SwiftUI performance Apple Developer Documentation
- Understanding hangs in your app Apple Developer Documentation
- OSSignposter Apple Developer Documentation
- Optimize SwiftUI performance with Instruments (WWDC25) Apple
- Profile, fix, and verify: Improve app responsiveness with Instruments (WWDC26) Apple
- Xcode 27 Release Notes Apple Developer Documentation
- Using Instruments to profile a SwiftUI app Donny Wals
- Xcode Instruments: Profile, Fix, and Verify Performance Antoine van der Lee, SwiftLee