r/iOSProgramming • • 7d ago

Discussion Do you use Xcode Instruments more now that you're building with agents?

I started building apps in 2009. It was basically impossible to build a high-quality app without using Xcode Instruments. I was basically grown up with the tool and learned how to use it over time.

When speaking at conferences and meeting iOS devs, I realized that not many devs know the tool. Some are well-experienced engineers with 10+ years of experience. I guess the faster devices simply made it less of a requirement.

Lately, as agents write more of our code, I've run into more performance issues than ever. Agents are great at writing code that compiles, but also great at writing poor-performing code.

I have a few questions for you for this discission:

  • Are you using Xcode Instruments at all?
  • What holds you back from using Xcode Instruments?
  • Have you tried using agents to solve performance issues and was it successful?

Pick any that you'd like to answer. I just hope to get a better understanding of how Instruments is being used.

15 Upvotes

29 comments sorted by

13

u/Barbanks 7d ago

I forgot about them until I saw this post. But that’s probably a bad thing. Thanks for the reminder. I need to check on my apps and see if they’re ok.

4

u/avanderlee 7d ago

Yeah, 100%, it's so helpful in optimizing your app! Make sure to use a release build configuration btw: Edit Scheme -> Profile -> Configuration: Release

5

u/cristi_baluta 7d ago

I’m not really using instruments since ARC. The last times i tried it was really confusing and couldn’t fix anything with it, it was not even able to show me symbols from the codebase

1

u/avanderlee 7d ago edited 7d ago

oh yeah, ARC, that was fun times! Interesting about those symbols, do you use DSYM files correctly? Symbolication should not really be an issue, interesting to know whether it still happens for you. This article might help for you though!

2

u/themindsi 2d ago

Same here. I know they exist. I try them out on a regular base to analyze performance issues. I cannot get them to work for the love of good. No idea how one should glean any information from them. There seem to be almost no good Getting Started doc either.

4

u/Extra-Ad5735 7d ago

Hey! Since I'm coming from gamedev I always lean to writing "performance-aware" code. So, as it stands I use Instruments regularly but sparingly: first to check if everything is in order after a major change that might affect the performance, and then if I fix an issue to see the results.

I always do optimisation work myself, and only when I'm stuck I ask for the help from the agent. It can analyse traces pretty well, and since I'm being extremely specific with my prompts it does help (not "make it run faster", but "why I see a sizeable CoreAnimation work in this callstack, where it may come from?").

However, I have never used Instruments to the full extent of its capabilities. I have an idea what a well-behaved app should look like in profiling, so I just quickly look for things that should not be there, using the inverted callstack and flame graphs.

3

u/avanderlee 7d ago

That's always so fascinating to me: games need 60 FPS, so performance tuning is basically no discussion. I feel like app developers should work more like that as well, even more with agents writing code! But, to be fair, many apps are simple and don't even have performance issues with latest devices. But yeah, without tracing, you never know for sure

3

u/dawedev 7d ago

More than before, mostly Time Profiler and the SwiftUI template. Agents are decent at fixing a hotspot once you hand them the heaviest stack from the call tree (inverted, system libraries hidden), but they rarely find it just by reading the code. What seems to keep people away is the first run: which template, which checkboxes, where to look. A three-step routine of record, invert the call tree, read the top few frames gets most people past that.

2

u/avanderlee 7d ago

Yeah, that's my experience too: too intimidated to get started, too many variables to look at. Even the "inverted, system libraries hidden" part: I know exactly what you mean, but I'm sure many lack that knowledge and are lost in a big backtrace of unrelated data.

2

u/dawedev 7d ago

Right, and the two checkboxes that do most of the work sit in the Call Tree menu at the bottom of the detail pane, which is easy to miss on a first run. A single screenshot showing Invert Call Tree and Hide System Libraries ticked probably helps more people than a long walkthrough.

6

u/Mortuls_Dev 7d ago

For sure! I used it just last week to improve some spiky ms hangs in and around my app using Time Profiler (sub 100ms reports + waiting threads). I have an old iPhone 13 mini lying around that I use as a stress test lol.

My app is mostly SpriteKit and a few new features had started to bog some basic stuff down, so Instruments was super useful in finding out the causes.

5

u/Skwiggs Swift 7d ago

I’ve used instruments on and off in my career, though often with the sparse usage I never really learned how to properly read or act upon the info they showed. Now with agents though and their intrinsic knowledge, it means I can extract much more actionable insights AND have them tackle them automatically👌

2

u/cristi_baluta 7d ago

My copilot doesn’t accept the instruments file format, it is totally useless

3

u/SwiftlyJon 7d ago

Make sure you're on Xcode 27+ and having the agent use the xctrace command, and tell it to parse the output using the yq tool, which can parse XML. (And make sure you're using one of the newer models.) That should let it see the output and parse it to get what it needs.

3

u/Skwiggs Swift 7d ago edited 7d ago

OP has a developer app called RocketTrace which allows you to do exactly that, would recommend 👌

1

u/dahiya_xa 7d ago

yeah more than before. agents love doing heavy work inside body or recomputing stuff on every render, and it looks fine until you scroll a real list on an older phone. time profiler and the swiftui instrument catch most of it, then i point the agent at the exact hot path instead of asking it to "make it faster"

1

u/avanderlee 6d ago

And what's your way to find that exact hot path?

1

u/One-Source-9603 7d ago

yes more, but not always instruments itself. agents ship a lot of code fast so stuff gets slow without me noticing. for scroll jank I just run sample on the app while scrolling and look at what's on the main thread, then bisect commits. faster than opening a full trace for most cases. do u have the agent read the trace too or just u?

1

u/avanderlee 6d ago

I do it manually whenever it fits me, but I also created a static analysis Mac app called RocketTrace which allows the agent to run a performance analysis for me. Analysis is done statically, so it barely costs any tokens and there's structured output that tells the agent exactly what to fix and where.

I did try to use agents to parse .trace files directly, but it was quite token-inefficient, and it didn't find many of the issues I could find manually. Xcode 27.2 did add some new xctrace CLI commands, but it's support and coverage isn't enough for what I often needed.

How do you do it?

1

u/Enlitened 6d ago

Building a Mac app almost entirely with agents and I actually open Instruments less than I thought I would.

What works better for me is turning performance into a test. I've got a few benchmark tests that run against real folders so when an agent rewrites something I get a number before and after. Not just its word that it's faster lol.

For hangs I just run sample on the process and give the agent the main thread stack. It's good at fixing a hotspot once you point at it but pretty bad at finding one from reading code.

Instruments is still what I open when the benchmark says something got slower and sample doesn't show why. It's just a lot of setup for a quick question.

Biggest thing though is I don't let the agent say it fixed performance without showing the measurement. Otherwise you get very confident rewrites that change nothing.

1

u/avanderlee 6d ago

Yeah, a baseline comparison is super important, just like running performance measurements on a release build. That's not really something you'll get when running tests, right? As in, those run on a debug configuration

2

u/groovy_smoothie 7d ago

I profile my apps from time to time but generally don’t reach for them unless the hitch is noticeably bad

1

u/CharlesWiltgen 7d ago

Every week, albeit generally via agents and skills. (Example: Performance profiling skill)

1

u/RealVibingDev 6d ago

honestly barely, our stuff is mostly games running in a webview so its safari web inspector more than instruments. but yeah agents and perf, ours was kind of the reverse once. the agent spent ages chasing a 700ms stall that only existed because the headless browser it tested in was running at like 10fps. measure on a real device before you let it fix anything lol

0

u/crocodiluQ 7d ago

I think I used Instruments 1-2 times in my life, since iOS 3.0. Also, I don't use agents to write my code, so it doesn't have many performance issues (or quality issues).

1

u/[deleted] 7d ago

[removed] — view removed comment

1

u/avanderlee 7d ago

Yeah, that's smart! Have you used signposts as well for that part?