A key talent for each app developer is with the ability to profile your app’s efficiency. Your app would possibly look nice on the floor, but when it doesn’t carry out properly, it’s going to really feel off—typically subtly, typically very noticeably. Lovely animations, slick interactions, and huge knowledge units all fall flat if the app feels sluggish or unresponsive.
Nice apps reply immediately. They present that you just’ve tapped one thing straight away, and so they make interactions really feel easy and satisfying.
To verify your app behaves like that, you’ll must control its efficiency. On this publish, we’ll take a look at how you should use Devices to profile your SwiftUI app. We’ll cowl find out how to detect sluggish code, monitor view redraws, and perceive when and why your UI updates. For those who’re focused on a deeper dive into SwiftUI redraws or profiling sluggish code, try these posts:
We’ll begin by constructing your app for profiling, then take a look at find out how to use Devices successfully—each for SwiftUI specifics and basic efficiency monitoring.
Constructing an app for profiling
Step one is to construct your app utilizing Product > Profile, or by urgent Cmd + I
(sidenote: I extremely suggest studying shortcuts for command you employ ceaselessly).

This builds your app in Launch mode, utilizing the identical optimizations and configurations as your manufacturing construct.
That is essential as a result of your improvement construct (Debug mode) isn’t optimized. You would possibly see efficiency points in Debug that don’t exist in Launch. I not too long ago had this occur whereas working with giant knowledge units—code ran fairly horrible in Debug was optimized in Launch to the purpose of now not being an issue in any respect.
When this occurs, it often means there’s some inefficiency underneath the hood, however I wouldn’t spend an excessive amount of time on points that disappear in Launch mode when you’ve got larger points to work on.
As soon as your app is constructed and Devices launches, you’ll see a bunch of templates. For SwiftUI apps, the SwiftUI template is often the best selection—even in case you’re not profiling SwiftUI-specific points. It consists of the whole lot you want for a typical SwiftUI app.

After selecting your template, Devices opens its essential window. Hit the pink document button to begin profiling. Your app will launch, and Devices will begin amassing knowledge in real-time based mostly on the devices you chose. The SwiftUI template collects the whole lot in real-time.

Studying the collected knowledge
Devices organizes its knowledge into a number of lanes. You’ll see lanes like View Physique, View Properties, and Core Animation Commits. Let’s undergo them from high to backside.

Observe that I’m testing on a bodily gadget. Testing on the simulator can work okay for some use instances however outcomes can differ wildly between simulators and gadgets because of the sources accessible to every. It’s all the time beneficial to make use of a tool when testing for efficiency.
The View Physique lane
This lane reveals how usually a SwiftUI view’s physique
is evaluated. Each time SwiftUI detects a change in your app’s knowledge, it re-evaluates the physique of any views that depend upon that knowledge. It then determines whether or not any youngster views must be redrawn.
So, this lane primarily reveals you which of them views are being redrawn and the way usually. For those who click on the timing abstract, you’ll see how lengthy these evaluations take—whole, min, max, and common durations. This helps you establish whether or not a view’s physique is fast or costly to guage.

By default, Devices reveals knowledge for the whole profiling session. Which means a view that was evaluated a number of occasions could have been triggered by totally different interactions over time.
Often, you’ll wish to profile a selected interplay. You are able to do this by dragging throughout a timeframe within the lane. This allows you to zoom in on a selected window of exercise—like what occurs whenever you faucet a button.
When you’ve zoomed in, you can begin to kind a psychological mannequin.
For instance, if tapping a button will increase a counter, you’d count on the counter view’s physique to be evaluated. If different views just like the button’s dad or mum additionally redraw, that is perhaps sudden. Ask your self: did I count on this physique to be re-evaluated? If not, it’s time to look into your code.
In my publish on SwiftUI view redraws, I clarify extra about what may cause SwiftUI to re-evaluate views. It’s price a learn if you wish to dig deeper.
View Properties and Core Animation Commits
The View Properties and Core Animation Commits lanes are ones I don’t use fairly often.
In View Properties, you may see which items of state SwiftUI tracked in your views and what their values have been. In principle, you may work out how your knowledge mannequin modified between physique evaluations—however in observe, it’s not all the time straightforward to learn.
Core Animation Commits reveals how a lot work Core Animation or the GPU needed to do when redrawing views. Often, it’s not too heavy, but when your view physique takes a very long time to guage, the commit tends to be heavier too.
I don’t take a look at this lane in isolation, however it helps to get a way of how costly redrawing grew to become after a physique analysis.
Studying the Time Profiler
The Time Profiler is perhaps probably the most helpful lane within the SwiftUI Devices template. It reveals you which of them code was working on which thread, and the way lengthy it was working.
You’re primarily seeing snapshots of the CPU at quick intervals. This provides you perception into how lengthy particular features have been energetic.
When profiling SwiftUI apps, you’ll often be focused on code associated to your knowledge mannequin or views. If a operate updates your knowledge and seems sluggish, or if it’s referred to as from a view physique, which may clarify a efficiency problem.

Getting comfy with the time profiler takes a little bit of observe. I like to recommend enjoying round with the decision tree settings. I often:
- Separate by thread
- Invert the decision tree
- Disguise system libraries
Typically, I tweak these settings relying on what I’m looking for. It’s price exploring.
In abstract
Profiling your code and understanding find out how to use Devices is important if you wish to construct responsive, high-quality apps. As your app grows, it will get more durable to mentally monitor what ought to occur throughout an interplay.
The difficult half about utilizing Devices is that even with a ton of knowledge, you have to perceive what your app is meant to be doing. With out that, it’s laborious to inform which components of the information matter. One thing is perhaps sluggish—however that is perhaps okay if it’s processing a whole lot of knowledge.
Nonetheless, entering into the behavior of profiling your app usually helps you construct a way of what’s regular and what’s not. The sooner and extra usually you do that, the higher your understanding turns into.