2026-10-29 • 2:52:48
Learn how to maximize your app’s performance and efficiency with Apple tools and technologies. In this online event, you'll explore how to identify performance opportunities and use Xcode and Instruments to gather and analyze key diagnostics. You’ll discover how to derive actionable insights from your data, including using coding agents to assist in building optimizations. You’ll also have the chance to take part in a Q&A with Apple experts.
Speakers: Phillip Azar, Cole Imhoff, Joel Middendorf, Shefali Saboo, Adenine Griffin, Luca Bernardi, Steven Peterson
Downloads from Apple
Transcript
Good morning, everyone. All right. And to everyone tuning in on the live stream, right there, good morning, and welcome. My name is Phil. I’m excited to be here with you all today. My team is a team that leads efforts around performance focused on apps. And welcome to the Developer Center here in Cupertino. Yes. All right. This is one of four Developer Centers around the world. There are some other locations in Bengaluru, Singapore, and Shanghai. And soon, Europe will be home to the fifth Developer Center, in Berlin, later this year.
Nice. This center is part of Apple Park, and it’s a great place for events like this. This room is Big Sur. It’s designed for in-person presentations, studio recordings, and live broadcasts. There are also labs, briefing rooms, and conference rooms. You’ll be able to experience all of these later in the day.
Here’s an overview of our agenda today. The focus today is power and performance, as I’m sure you all are aware, viewed from the lens of what I imagine is our favorite tool right now, or set of tools: coding agents. There’s a lot to cover after this welcome presentation. Cole is going to take you through how to get started with performance.
Then Shefali is going to talk about how to combine some of the agentic coding tools and harnesses you already use with the performance data to find opportunities for your apps. After a short break, Adenine will work how to break down some power problems in your app with practical techniques, and Luca from the SwiftUI team is going to demonstrate how to use agents with the SwiftUI specialist skills.
Then we’ll break for lunch, as I’m sure we all will need it. And after lunch, we’ll be holding a Q&A here on stage with a panel of experts. For those of you here in person with us, you can join us here for that Q&A, or afterwards, you can proceed directly to the labs, and we’ll be holding those all afternoon.
A quick note for everyone here in person: there’s an open Wi-Fi network you can connect to to stay in touch with us throughout the day, with no password required. There’s also power outlets in all of your seats. They’re located at the front of the armrests. Now, these presentations, they’re meant to be a special experience just for you, both online and in person. So please don’t record video or live stream during the presentations. We’ve got all that covered for you.
You’re welcome to take photos so you won’t miss a thing. And with that small request out of the way, today’s activities are about helping you give a boost to your app’s speed and efficiency. This means things like making your app launch quickly when somebody taps on the icon, remaining responsive to gestures and input, and animating smoothly and being efficient, having the smallest impact to shared resources like battery and storage. We believe these are the qualities of any great app.
When you make performance improvements to your app, it reduces the friction that people experience using that app. And developers tell us all the time that when they really focus on performance, this translates to a better product and even better business outcomes. Here’s an example. Notion is a productivity app with one goal in mind: to help people build beautiful tools for their life’s work. And it reaches more than 100 million people around the world. Notion has been migrating their app’s interface to SwiftUI, and now that the app is almost entirely native, the app launches twice as fast.
This is what Austin Louden, their mobile platform lead, had to say about this: performance is critical. Time and time again, we’ve demonstrated that when we improve performance, all metrics go up: activation, page creation, every engagement metric. This goes to show you that when you invest in the performance of your app, people feel those improvements, and they get so much more from your product.
And here’s another team. Tinder has done some great work making their app more responsive, with a dramatic improvement to their app’s hang rate in the past year. Here’s what the Tinder team has to say about this: we’ve improved the user experience and are seeing higher engagement as a result. The time and effort you spend on performance translates to better experiences, bar none.
Now, making performance improvements has changed for a lot of us with the introduction of agentic coding and agents. So throughout today’s presentations, we’ll share some tips and techniques to not only help you get the best performance out of your app, but to get the most out of these tools as well. I’m really excited for us to get started today. And let’s get started with our first presenter. Please help me welcome Cole to the stage to tell us how to get started with performance.
Get started with performance
Good morning, everyone. My name is Cole, and I’m a performance evangelist here at Apple. And I’ll be joined shortly by my colleague Joel on the performance engineering team. So this morning’s session is an orientation. I’m going to discuss where to get started with performance. First, I’ll cover how you figure out what matters the most in your app when it comes to performance. And then I’ll dive into some stuff that you can all try even before you leave here today to make the biggest improvements to your app.
I’ll touch on what to do when problems get a bit tougher to solve, and then I’ll leave off with a few thoughts on how the best teams in the world build performance into their workflows. So I’ll start with considering what matters. So many of you have a product, an app. That’s why you’re here today. It lets people maybe stay in touch with others, create things. Maybe it brings them your great content.
And on the other side, of course, you have your audience, the people using your app, and they want all that cool stuff it has to offer. So what sits in between people using your app and what it can do for them? Well, there might quite literally be some things in the way that you can point to. Maybe your app requires someone to log into an account. Maybe it requires someone to provide some personal information before it provides some useful content.
Maybe it takes people through some onboarding screens to get to your app’s goodness. Now, most likely someone, most likely someone didn’t… Kind of… Someone didn’t open your app just for the joy of logging in, right? They came for something that your app has to offer. And there’s other things that are even more implicit, like if the app has some novel custom interface controls that don’t follow the platform’s convention. Now someone has to learn those things before they get started in your app. They’ve got to figure out what they can tap on, and what happens when they do. And that adds even a bit more distance from your content.
But some things are even more implicit, like performance, when an app just seems to take a little bit longer to launch than others and be usable, or if an app has choppy animations and maybe becomes unresponsive to input. These are things that, you know, maybe people can’t describe, but they feel it, and it just adds friction, and it adds distance from everything that your app has to offer. So as Phil said earlier, reducing or improving performance and spending time on working on performance helps you reduce this friction.
And if you want to make this better, there’s kind of a few logical places you could start. You might be tempted to just jump right into your code, and you might have some intuition on what’s causing performance problems. And so you just want to start there. Another thing you could do is you might just be tempted to take measurements of your app and kind of then approach it more scientifically.
Or maybe you have people telling you what they think about your app’s performance. Now, the truth is, there’s kind of a place for all of this, right? Sometimes your intuition and feedback from others is the key insight you need to unlock specific problems. But I put it to you that the best place to start is to be scientific about it. You can’t fix what you can’t measure. So your first goal is measuring what matters the most to you in your app.
And what matters is going to be different for pretty much everyone here. So here’s an example. This is an app that lets people capture photos and share them with friends and family. Now, people using this app are often in kind of spontaneous and unplanned moments. So what they might really care about is getting to the camera’s viewfinder as quickly as they can.
So what you might measure here is measuring the time it takes from tapping the app icon to the time that the viewfinder is ready to use. But not all apps are the same, even an app that uses the camera. So here’s a different example. This is an expense tracker app.
It lets people scan receipts when they’re traveling for work. Many, maybe some of you are going to use an app like this soon. It lets people scan receipts. So when a photo is taken, the app will use some intelligence features to read the receipt and get the person reimbursed.
So this is a little different. Someone using this app is maybe on the go, but they’re not capturing a candid moment. So something else might be important to measure, like measuring the time it takes from a captured receipt photo to the completion of the expense report. You should reflect on your own app and your own experiences and think about what really matters for most people using it.
And on top of the things that you define, there’s just some things that people expect every app to do really well. People expect all apps to launch and get to their content quickly, to be responsive to gestures and actions at all times, to animate and scroll all of its content smoothly, to be stable and reliable, and to be efficient with someone’s storage and battery.
Now, maybe this sounds a little obvious when you say it out loud, but what this does is identifying each of these qualities then lets you detect and fix problems in each of these areas. So for example, Apple platforms give you tools to measure your app’s launch time, and it tells you what code is responsible for slow launches.
And you can do the same things for when your app freezes and becomes unresponsive to gestures, which is called a hang. You can measure hitches, which are times when animations don’t render smoothly, and your app can detect other issues like crashes and high battery usage and excessive storage use.
This is how you find what really matters. You collect data for each of these areas, and then you build a plan for how you’re going to make improvements to your app. Now, that plan doesn’t have to be fancy. It can be an email. It can be a note. But here’s what goes into it.
Write down your priorities. Think about what people are going to really care about for what your app does. Come up with a way to measure each of those things concretely, and then set goals for yourself and your team to measure each of those, to improve each of those measurements. Use the tools and techniques that we’ll discuss today to actually make those improvements. And most importantly, start over and keep going.
Great code alone is not how fast and efficient apps get built. They get made by following a plan like this, and Apple’s developer tools, like Xcode, help you with the core of this process: measuring, setting goals, and making improvements. So this is what I’m going to cover next: how to use the tools to make the biggest impact to performance.
Now, if you have an app on the App Store with an active user base, the best place to start is right in Xcode, in the Xcode Organizer. If your app is already on the App Store, the Organizer is doing a lot of this planning work for you already. You just have to start using it.
Xcode Organizer measures the performance of your app when people use it, and for each area of performance, Xcode will even tell you what an achievable goal is for your app. The Organizer compares the latest version of your app to previous versions and to other similar apps. And when the latest version has room to improve in that comparison, it provides you a recommendation, a goal to work toward.
In this example, the Organizer says that the most recent version of the app has a hang rate of 12.6 seconds per hour, but previous versions of the app were a lot better, around 1.2 seconds. So there’s clearly a lot of room to improve here. And once you identify something that you want to improve, the Organizer also tells you which part of your code to investigate. Reports in the Organizer show aggregated reports of the code that was running when problems occurred.
For example, here’s a hang report. It tells me that someone using an iPhone 14 Pro Max had my app hang for nearly 3 seconds, and most of that time was in this specific code path. And it’s not alone. Over 2,800 hangs have been detected with the same pattern.
And one of the best parts about this tool is that this information appears automatically. You don’t need to turn it on. And the platform takes care of protecting privacy by obtaining consent from users before it collects this data and then shares it with you. And the Organizer isn’t just used in isolation. You can combine it with the coding intelligence features of Xcode. So to show you how this works in practice, here’s Joel.
Great. Thanks, Cole. So hi, everyone. I’m Joel. I’m an OS performance tools engineer here at Apple. I’ve been working on the Expenses app that Cole talked about. It allows me to submit my expense reports to the company so I can get reimbursed. To show you the app, I’ll build and run it from Xcode.
I’m on the Reports view, and these are the expense reports I filed over the past two years. If I want to view or update any of the reports, I can just tap it. I’ll tap my Cupertino on-site trip from August, which is down here. And now I’m showing the list of expenses I entered for that trip.
For each expense, I was required to attach a photo of the receipt as proof. So I’ll tap the hotel expense, for example. And the app shows me a photo of that receipt. The app also tracks my spending for the year. I’ll tap the Spending tab bar button at the top.
Okay, that took a while, but I’m finally in the Spending view. That might be a hang in my app, and I’ll get back to that. I really like this new feature we added to the latest version. When I scroll to the bottom of the Spending view, the app now shows me all my receipts for the year as thumbnail images. But I’ll try to reproduce that hang again. To do that, I’ll switch between the tab bar buttons at the top a few more times.
And yep, the animation freezes every time I tap Spending. So there’s a hang there I need to fix. So now I’m concerned. I recently shipped this feature, and I want to know if this is happening to people in the field. Fortunately, Xcode Organizer can help me answer that. To open the Organizer window, I’ll go to Xcode’s menu and choose Window, then Organizer.
On the left are the diagnostic reports and metrics. Each of these items shows power and performance data for my app’s usage from the field. Right now, I’m on the Insights overview, which is a great place to start. The Insights overview presents a summary of the top power and performance issues, if any, that need my immediate attention. The Insights overview is calling out hangs for the latest version of my app. At the top is the Hangs metrics chart.
Each bar indicates the hang rate in seconds per hour for a version of my app that I released in the App Store. A taller bar means a higher hang rate. The rightmost blue bar is for the latest version of my app, and the text to the right of it indicates that the average hang rate is 12.6 seconds per hour.
And my previous app versions are 1.9 seconds per hour. So my latest version is hanging a lot more than my earlier releases. There’s also a horizontal dashed line on the chart, which indicates my recommended metric goal. I’ll hover my pointer over the dashed line for more details. And a popover tells me I should aim for a hang rate of 1.2 seconds per hour. This goal is based on historical performance of my earlier app versions. Below the chart is the top contributor section.
This is where the Organizer lists the functions and methods in my code that contribute most to hangs. The top function in that list is my decode function in the ReceiptThumbnailCache class. I want more information on this hang, so I’ll click the arrow button next to the immediate right of the decode function.
And Organizer takes me to the hang report for the decode function. In the view is one of the hang logs that was reported for this hang. This particular hang log indicates a 2.86-second hang occurred, and two and a half of those seconds were spent in this code path.
Below that are statistics. This section shows the OS versions this hang occurred in. And the number inside the donut chart indicates that there are at least 12,000 logs for this hang. So yes, this hang is happening a lot in the field. In the middle of the view is the call stack.
This tells me the path the code took when the hang occurred. The frames in gray indicate system code, and any frames in white are my app’s code. The frame in white is my app’s decode function, and it’s running on the main queue. Below that, decode calls into ImageIO to create a thumbnail.
And below that is where the JPEG image actually gets decoded. So I think this tells me that my decode function is creating JPEG thumbnails of my receipts on the main queue. That’s not great, because if I’m doing heavy work on the main queue, that can block the app’s UI and user input. I’ll click the arrow button next to the decode function, which will take me to the code so I can investigate and fix this.
And I’ll select my Expenses project so I can open the source code. Now I’m in the decode function, and Xcode has highlighted the line with the hang in red. Sure enough, on that line, there’s that CGImageSourceCreateThumbnailAtIndex call from the call stack. This is where the JPEG thumbnails are created. That’s expensive work, and it belongs off the main queue.
I have an idea how to fix this, but I’ll use the coding assistant to explain why the decode function is performing this work on the main queue in the first place. To do that, I’ll return to Xcode Organizer. Near the top right of the Organizer window is a Generate Recommendations button. I’ll click the button and select my project again.
Now I’m in the coding assistant. The agent is fetching the logs and analyzing my source code, and it should tell me what’s wrong and recommend the fix. What I really like about this feature is I can have a conversation with the agent about this issue. If something isn’t clear, I can ask the agent follow-up questions about this hang, and Shefali will have more to share about this feature later. So once the agent has completed its analysis, I’ll scroll up in the conversation and read what it recommends.
Okay, it’s finished its analysis. Scrolling up. The agent issued a couple commands looking for keywords in my project and config files. And scrolling down some more. The agent found the problem. The decode function runs wherever its caller does, and the caller is on the main actor. So the expensive work of turning every receipt photo into a thumbnail ends up on the main queue. Scroll down some more.
It’s also telling me that the fix is a single line: mark the decode function as @concurrent, which tells Swift to always run my decode function off the main actor. I’ll tell the agent to go ahead and apply the fix. Oops. Now the agent should apply the fix and show the corresponding diff of the changes it made.
Great. Now I’ll test this change by rebuilding and running the app by clicking the Run button from the toolbar. Hopefully, the performance feels better this time. And I’ll switch between the Reports and Spending tabs to check whether that hang is still there. Okay. Feeling better? Five, six, seven. Okay, that’s much better.
No more hanging each time I reopen the Spending view. The first time, it looked like it hung. That’s maybe something to look at later, but definitely, each time I come back into Spending, it is not hanging anymore. So it looks like we fixed an issue. How about that?
Great. So to sum up, check the Xcode Organizer regularly to find performance issues in your app. Analyze the issue, and use the coding assistant if you need help. Fix the issue, then return to Xcode Organizer to move on to the next issue, repeating the process. Make this part of your development workflow, and you can do it all without leaving Xcode. And with that, I’ll send it back to Cole. - Cole, over to you. - Thanks, Joel.
So if you’re shipping an app on the App Store today, find the biggest impact opportunities in the Organizer. Review your app’s metrics and make a goal for yourself and your team using Xcode’s recommendations. Use the reports to track down parts of your code that are causing real performance problems for people, and then use agents to help build fixes, if agentic coding is part of your workflow.
Next, I’m going to talk a bit about the gnarlier problems. Some types of problems can’t be surfaced in the Xcode Organizer, and they require a different approach. That could be, for example, if you have a brand-new app or a new feature, and it’s just not in the hands of many people yet, or when the app has a specific problem that only occurs in some specific states, like locations or network conditions, or maybe when the app runs for the first time, or maybe you encounter a problem that’s actually pretty rare and only occurs in some very specific cases. For problems like these, you need a way to collect data under these conditions that you can reproduce on your device, rather than relying on a distribution of reports from people.
And a great tool for that is the Instruments app. Instruments lets you profile your app. You use it to record a period of time while your app is running on your own device, and then Instruments captures a highly detailed recording of what the app was doing. Once that’s done, different tools, each called an instrument, lets you analyze that timeline.
From your Xcode project, just navigate to the Product menu and then select Profile. And when you do this, you’ll first choose a template. A template contains a different set of instruments that you may want to use, depending on the type of problem you’re investigating or the technology that you’re using.
This includes different types of performance problems, like animation hitches or launch time, or different technologies, like Foundation Models or network or SwiftUI. You can also just choose a blank template and then add in the specific instruments that you want to use. When you choose a template, you’ll click Record. Instruments will launch your app, and you’ll use your app for a while while it’s recording to gather data.
Now, when you stop the recording, Instruments gives you this rich timeline that you can dive deep into. This is an incredibly powerful tool, and it’s one that you can get really good at with practice. So if you haven’t used this before, I highly recommend checking out the tutorial “Profiling apps using Instruments.” And there’s a great session from WWDC called “Profile, fix, and verify: Improve app responsiveness with Instruments.”
Now, Instruments is just one source of additional data, but there’s also some others that you can use right on your iPhone or iPad. If you’ve connected your iPhone or iPad to Xcode at least once, navigate to the Developer menu in the Settings app. Here’s a few of my favorite tools that you’ll find there.
The Hang Detection tool detects when your app becomes unresponsive, and then it immediately generates a diagnostic report that you can AirDrop over to your Mac later for review. And you can even profile your app without your Mac nearby. With Performance Trace, you can start profiling right from Control Center, and then later, you can inspect that trace file on your Mac.
And one thing that’s really cool for battery life issues is the Power Profiler trace option that lets you collect power use data over time. This is really great for apps that spend a lot of time in the background, and you want to understand the power impact of that.
So for tougher problems, it’s all about finding more ways to gather data. Use Instruments to gather rich recordings of your app’s activity on a timeline. Gather diagnostic data with tools right on your device, like on-device hang detection. And once you have this data, analyze it to figure out which parts of your code are causing the performance problem. And Shefali, later this morning, will go even more in depth on how you can do this using agents.
Performance is part of the quality of your app, in the same way that you might be tracking crashes or bugs or other quality problems. I encourage you to think about how performance fits into your real development workflow and build a practice around it. Earlier, I proposed this as a model for your performance plan.
Now, to make a plan like this happen, there’s a few things that teams that do really well with performance, they bake this plan into how they go about their work every day. Here are some best practices. First, get started. Pick a real starting point. Maybe it’s your next release, and just use that starting point to figure out what your app’s performance really is like today.
Once that’s done, track how performance changes in the following release, and assign someone to this task. And now that you have that data, start to make real consequential decisions on this data that you collect. For example, if severe performance problems arise, classify them as release blockers, just like you would if you have features that aren’t working right, and advocate for performance improvements to be part of the scope of an upcoming dedicated release.
And if performance issues arise, track them as bugs to make sure that progress toward a fix is being tracked. And most importantly, celebrate the improvements. I know firsthand that chasing down milliseconds of improvements on one code path can feel like thankless work sometimes. But people feel this work that you put into it and the craft that you put into these problems, and those wins deserve celebration.
So when you want to take performance to the next level, there’s also even a few more tools and frameworks that I haven’t talked about that you can also use. You can bring agents into the fold to help you improve performance. You can write performance tests to flag issues automatically. And you can make it even easier to get to the bottom of really tough issues with tools like StateReporting and MetricKit. These will all be discussed more in depth today, but after this session, check out the WWDC video “Meet the new MetricKit.”
So if you’re just getting started, here are my tips for you. Start by identifying the experiences that matter the most to you, and find ways to measure them concretely. Open up Xcode Organizer to find what you could fix today that would have the biggest impact for people. For tougher issues, turn to Instruments to profile your app on device, and collect data with on-device tools like hang detection, and keep at it with every release. Bring performance into your work as part of your craft of creating great apps. Thank you. All right. Thank you, Cole. That was great.
So the next session is for those of you using agentic coding tools, which is, I’m assuming, all of you. If you want to get the best possible analysis about your app’s performance using these tools, this session is definitely for you. So to get started with that, please help me welcome Shefali. Thanks, Phil.
Optimize your app with data and coding agents
Good morning, everyone. My name is Shefali, and I’m a performance tools engineer at Apple. Today, I’m going to share some techniques on how you can get the best performance from your apps when using coding agents. I’ll start with an experience I’m sure many of you might be able to relate to: improving an app that you already have on the App Store today. Then I’ll talk about solving performance problems during development. Finally, I’ll reveal some of my recommendations on how to identify trends and patterns as you evolve your app and ship many releases over time. First, I’ll start by talking about improving existing apps.
Agents read your app’s code for performance. That’s incredibly powerful. An agent can find a loop, understand what it’s doing, and reason about whether it’ll perform the way you expect. But often, what shapes your app’s performance isn’t the code at all. When your app runs, things get more complex. The settings people choose can dramatically change how your app behaves at any given moment. Different features might be turned on through feature flags or other conditions.
People also make their own choices about how they use your apps. How many photos are they saving? Which document formats are they working with? How many projects are they keeping open at once? Every one of these choices can change how your app performs. Then there are factors completely outside of your control: the quality of the network condition, how much memory is being used, the availability of other system resources, and everything else happening on the device at the exact same time. This matters a lot, especially when using coding agents on their own. Agents don’t have the information they need to reason about any of this.
What they can do is inspect your code and reason about its performance based on common patterns. But your code alone isn’t enough, not enough for agents, and honestly, not enough for any of us. So how do you fill in the rest of the picture with data? You need to understand how your app performs when it runs in a variety of these conditions. That’s data that you need to collect and then analyze.
For an app you’re shipping on the App Store, that data is already waiting for you, right? In the Xcode Organizer earlier, Joel showed you how the Generate Recommendations button can help fix the issues it finds. But that’s not the only way to do this work. When you have an app on the App Store, Xcode makes the same performance data available to coding agents through the Model Context Protocol, or MCP server, in Xcode. Both the coding agents in Xcode and external agents can use this MCP server.
With these tools, an agent can fetch your app’s top performance issues, along with detailed diagnostics reports. This includes slow launches, hangs, crashes, high energy usage, and so much more. These reports come from real devices that encountered real performance issues in your app, so they capture a representative sample across that variety of conditions we talked about earlier. You and your agents can cross-reference each of these reports with your app’s code to figure out exactly what to improve.
Earlier today, you learned how you can ask an agent for a recommendation on a specific performance issue, but this data can do so much more. For example, agents can help you plan where to spend your development time. You can ask your agent to review all of your app’s hang reports and recommend optimizations in priority order based on their potential impact to the hang rate.
You can have it perform a triaging exercise where it proposes fixes in order based on level of risk for each change. And before you take on a larger fix, your agent can help you plan how to test for that issue going forward so it doesn’t come back as a regression. All of this works great while you’re in the Xcode Organizer and in Xcode. But here’s the best part: it can keep working for you even when you’re not.
These tools give you what you need to build a pipeline that monitors your app’s performance and proposes fixes on an ongoing basis. This starts by gathering data from either the Xcode MCP or fetch directly from the server using the App Store Connect API. Both of these are sources of data that give you diagnostic reports about performance issues in your app.
These reports can be handed off to coding agents to analyze and fix and prepare a pull request for your review. When you’re ready, you can review each pull request and merge it in, shipping meaningful performance improvements to the people using your app. It’s a process that keeps your performance data working alongside you with every release. I’ll come back to this idea a little later.
Everything I’ve covered so far works great once your app is on the App Store. But what if it isn’t there yet? Maybe you’re building a new feature or even an entirely new app. Building something new is a real challenge because of all of those factors we talked about a little earlier: settings, feature flags, the variety of ways in which people use your app, and everything else happening on the device.
In this case, you don’t know how it’ll behave in the real world yet. There aren’t people using it. So the Organizer doesn’t have data you can learn from for new features or new apps. The approach is actually the same. You still can’t reason about all of these performance factors without data. You just need to use different strategies to collect this data. One of the best ways to gather this kind of data is to profile your app. You can do that with Instruments or by capturing a trace using the on-device tools in Developer settings.
When you do that, you get a detailed timeline of where time was spent as you use the app, and you can visualize operations that occurred in different ways. For example, in this Instruments trace, the Hangs instrument shows that the app was unresponsive to input for over half a second. During that time, the system load track shows the load the system was under. The thermal state track shows whether the device was under thermal pressure, and the main thread track lets me dig into exactly what my app was doing.
When you examine a trace, you use Instruments. When a coding agent examines a trace, it uses a command-line tool called xctrace. In 27.2, xctrace has expanded capabilities that make it even easier for agents to find and fix problems. Xcode also comes with skills that equip the agent with everything they need to understand and act on the data in Instruments traces.
xctrace triage analyzes your trace for common performance problems, like hangs, and gives you a clear, human-readable summary of where the problems are and which code paths need further investigation. In this example, running xctrace triage on a trace with a hang shows that there was one hang lasting roughly 3.35 seconds. During that hang, the main thread was using less than 1% of the CPU. This means that the main thread was stuck waiting on something. xctrace triage also points to where to look next. It gives you the exact command to dig into that window of time.
There’s another new command: xctrace show. It provides access to all the great visualizations in Instruments, but as text. This enables agents to conduct the same type of performance investigations you would with Instruments. When you use Instruments, it’s often helpful to drill down into a specific slice of the timeline. The show command gives agents the same ability.
Here, I’m looking at just the time window of the hang across every thread in my app, and now it’s clear what the main thread spent most of its time waiting on. A background thread was busy for over a second, rendering a preview image. This new format is not only easy to read, but also token efficient. So if your agent was spending tokens converting a trace to XML, point it to these new commands instead.
xctrace is a secret sauce that makes it possible for agents to get the same kinds of insights you get when you profile your app yourself. There is one key difference from doing this yourself, though. Agents need more context than you probably do about what was happening in your app over time. Consider a trace that has a Time Profiler track showing what code was run every millisecond.
When you open this in Instruments, you might intuitively remember what actions you took and approximately when. In this case, you’d remember that you launched the app and then opened a document, so your attention might go immediately to the spike in CPU activity shortly after you launch the app, when the document data was being parsed. An agent often doesn’t have this context. Sometimes it can piece this information together by looking at the functions called over the entire timeline.
But that can be expensive, and it doesn’t always work. Code paths don’t always line up neatly with the moments you actually care about. The best way to help your agent understand a trace is to annotate them with even more information. One of the things you can do is earmark periods of time that are notable and important in your app. You can do that with signposts, a feature of the unified logging system. For example, this app uses signposts to mark when someone starts opening a document and then again when the document is fully open.
The interval of time between these signposts can be visualized in the trace using the Points of Interest instrument. Now the agent can see what your app was working on and when. And it helps you too. Instead of relying on memory and intuition, you can find these points of interest right in Instruments. Here are some tips on how to create data-rich traces that coding agents can meaningfully analyze.
First, profile your app on real devices. Simulators have different performance characteristics and aren’t the best source of data. When you want to measure and track specific periods of time in your app, use the logging system to emit signposts. First, create an OSSignposter with the Points of Interest category.
Then, when the work starts, call beginInterval and give it a name. When the work is done, call endInterval with the same name, along with the state that beginInterval returned, so the signpost events are matched correctly. Now these intervals will be available in the Points of Interest track in an Instruments trace for you and your coding agent to reference.
Intervals like these are great for measuring specific tasks, but sometimes you want to capture something else, like the state your app is in. That could be any period of time when your app is in a particular mode or a feature is turned on. For that, consider using the StateReporting framework. It lets you describe the states your app is in and the transitions between these states.
First, get a reporter for your feature using a reverse DNS domain name. Then, whenever the mode changes, report a transition to the new state with a descriptive label. States are recorded by the logging system too, so they show up in your trace whenever signposts are captured. Finally, profile your app under a variety of conditions. Don’t stop at one trace. Capture many. The more traces you take, the better sample set you’ll have to work with. Perform actions in different orders, or work with different sets of data, and try different device conditions.
For example, the Network Link Conditioner lets you simulate a poor network connection, so you can find issues that don’t show up when everything is running smoothly. Now let’s see how all of this comes together. I’ll use Instruments and a coding agent to find and fix a performance problem in my app.
I have a notes app I’ve been working on, and I want to make it easy to identify when a hang occurs. xctrace and Instruments can help debug and solve these performance issues. To get started, I’ll enable on-device hang detection, which will give me real-time alerts at the top of my screen when a hang occurs. To enable hang detection, I’ll go to Settings and scroll down to the Developer pane.
Then I’ll tap on Hang Detection and enable the Hang Detection toggle. I’ll leave the hang threshold at 500 milliseconds to learn about even the briefest UI stalls. If I encounter any hangs, I’ll want to make sure they’re captured in a trace, so I’ll preemptively start an Instruments capture of this debug session.
The run destination for my project is already configured to my test iPad, so I’ll start profiling in Instruments by using the Command-I keyboard shortcut from within my project. The Command-I shortcut will build my app and install it on my test device and then launch Instruments. The last time I was using my app, I encountered a hang when saving a note. I want to reproduce that today, so I’m going to use the Time Profiler template.
The Time Profiler template already includes the Hangs instrument and Points of Interest instrument, which will be useful for visualizing the earmarked sections of my project. Now that my Instruments run is configured, I can start recording. I’ll click the red Record button in the top left corner of this window. This will launch my app on my target test device. I want to test the save path in my app, so I’ll start by opening the first note in the list, titled “Dragon Curve.” Now I’ll make a simple edit and tap Save.
I know that hang detection worked, because as soon as I tapped Save, a notification appeared at the top of my screen informing me of the hang. This particular hang was about 3 seconds. Now that I found a hang, I’ll stop the trace by clicking the Stop button in the top left corner of the Instruments window. I’ll save the trace to an easy-to-access location on my Mac and call it Trace-save-hang.
I’ll also name this run. I’ll call it “baseline.” Now that my trace is saved, I’ll confirm the hang was captured. This trace has a lot of data, so the first thing I’ll do is focus the trace to the hang duration. There is a severe hang for about 3 seconds in the Hangs track. I’ll focus on that.
Next, I’ll click on the bar that says Severe Hang and select Set Inspection Range and Zoom. Instruments zoomed in to remove all the other noise so that my trace is focused. And now that my trace is focused, I can inspect a couple more things. The first thing that stands out to me is that the Points of Interest track shows that this hang occurred during the rendering preview part of my app.
This is where I convert a note into a PNG to use as the preview in the notes source list in my app. A hang in my app means that the main thread was blocked, so I’ll also check what work is happening in my app during this hang. I’ll select the Time Profiler track and navigate to the detail view in the bottom half of the window. The call tree view shows that 95% of the hang time was spent doing work in this background thread. For more context, I’ll Option-click to expand the call stack.
The expanded call stack shows time being spent in NotePreviewExporter renderPNG, which is where I generate the note preview. This seems a little suspicious, but provides me with a good starting point for my investigation. Let’s have an agent do a deeper dive. Like I mentioned before, the agent will be able to use xctrace to review this trace just like a human engineer would. I’ll start this investigation by navigating back to my Xcode project and switching to the coding assistant.
Now I’ll start a new conversation by clicking New Conversation in the sidebar. I want the agent to analyze the trace I just took, so I’ll drag it from Finder into the conversation I just started. I’ll tell the agent to investigate the hangs in my app and describe the solution, and it’ll use the attached trace for context.
I’ll click Submit to start the conversation and watch as the agent goes to work. Hangs generally occur when non-UI work is done on the main thread, or the main thread is blocked, waiting on other work to finish. There are a few common anti-patterns that lead to hangs. One of the most prevalent are priority inversions.
This is when a high-priority task, such as main thread updates, are blocked, waiting on low-priority tasks to finish. This can be mitigated by avoiding shared locks and using the correct quality of service, or QoS, level. If your app uses structured concurrency, some best practices are making sure not to execute work on the main actor. Instead, wrap the long-running work in a nonisolated async function.
It looks like the agent is done and provided a summary of its findings. Let’s go through the transcript. The agent started by calling xctrace triage to identify a hang. It then analyzed the trace and found the root cause of the hang. It attributed this to a priority inversion in the preview renderer. Then the agent provided suggestions on how to resolve the issue. These optimizations sound reasonable. I’ll tell the agent to make the recommended changes.
Today, we’re discussing how the agent handles hangs, but xctrace can work for a variety of performance issues that I encourage you to play around with. The xctrace skills exist to find the needle in the haystack and help you pinpoint the root cause of a performance issue, so you can make a decision on how you want to resolve it.
These skills that are used in Xcode can be exported from the command line, so they can be used by any agent of your choice. The agent is done, so it’s time to double-check its work by capturing a new trace and confirming the hang is no longer there. I’ll build the changes and profile in Instruments with the Command-I keyboard shortcut, just like before.
To start a new run in the same trace file, I’ll click Next Recording in the top left corner. Doing this will preserve the configuration of my previous run, and my baseline trace will be just a click away in case I need to reference it. I’ll click the Record button in the top left corner of the Instruments window. And now it’s time to test the save feature again. I’ll make a small edit and tap Save.
Hang detection didn’t call anything out, which seems promising. I’ll stop the trace by clicking the Stop button in the top left corner of the Instruments window and manually inspect the trace. A quick scan along the timeline view doesn’t show a hang during rendering preview, which is also much faster now. I’ll commit these changes and put up a PR for the rest of my team to review after this presentation.
Using agents is incredibly convenient. While it enables quick iteration, it’s also a good idea to validate that the changes made by the agent actually do what they’re expected to do. In this specific example, the hang was resolved, and my app’s functionality was preserved in the process. Using Instruments, points of interest, and agents made it really quick and easy to identify and fix the hangs in my app.
So that’s how you can find and fix a performance issue today. Now let’s look ahead to how performance data and agentic coding can play a role. As you grow your app’s capabilities, as agents become a bigger part of your work, you may want to enrich the performance data you collect, just like I showed you how to do when collecting traces. Say you want insights on hangs in one specific part of your app, or how long launch takes when a certain feature is turned on. For that, you need data that has context built in, data that you can aggregate and analyze with your agent.
You may also want to analyze data from different audiences, like your internal users or beta testers. These challenges are exactly what the MetricKit framework is designed to solve. MetricKit delivers a daily report of your app’s performance metrics, as well as diagnostics whenever a performance issue happens, like a hang, a crash, or a memory issue.
This gives you the raw data to build your own custom dashboards, reports, or even a pipeline like the one I showed you earlier, where your agent makes performance work part of every release. MetricKit works for all audiences of your app, from internal users and beta testers to people who download your app from the App Store. If you send this data off the device, it will be subject to your own privacy and data collection policies.
Earlier, I showed you how you can use StateReporting to annotate your Instruments trace. It helps both you and your agent understand what state your app was in over time. In the 27 releases, StateReporting works with MetricKit too. By default, MetricKit gives you metrics for the previous day of usage, like showing a hang time of 6.7 seconds across all app usage.
But when your app reports its state, MetricKit can break down those metrics by each state. So instead of one hang time for all usage across your app, you get a separate one for each state, for example, when someone was actively using feature one, feature two, or feature three. MetricKit is the cornerstone of a fully agentic performance workflow, one built on real performance data.
As you aggregate more MetricKit data, you get an even richer picture of the performance problems that matter most to the people using your app. This can feed directly into your agentic workflow, so your agent can propose fixes as pull requests, release after release. Another key way to identify and fix problems early is with automated tests.
You can take parts of your code, break them into smaller pieces, and write performance tests around them. With XCTest, with agents, writing tests is easier than ever. Instead of writing every test manually, your agent can make sure all the new code you write has comprehensive test coverage to prevent performance regressions.
You can use the measure API in XCTest to gather performance metrics for a block of code. Compare your runs against your baseline to catch regressions, and investigate further with your coding agent. So where do you go from here? Harness the power of your app’s performance data to make meaningful improvements. Gather metrics and diagnostics from every source available to you: the Xcode Organizer, the Xcode MCP server, MetricKit, and your tests. Then put your agent to work on your app’s top performance issues.
Use Instruments and the new xctrace commands so your agent can work through traces efficiently, and adopt MetricKit and StateReporting to get the most data-rich insights for your app. I hope you’re all excited about how agents and performance data can work with you as you expand your app’s capabilities over time. Thank you.
Awesome. Thanks, Shefali. I’m sure none of you are going to have any more bugs in your apps anymore. Now we’ll have a short break. We’ll pick it up right back here at 11:30 a.m. Okay. Welcome back. Welcome back. I’ll let you folks get situated. Oh, there’s that QR code. As a reminder, throughout the day, we’re going to be taking note of your questions, and you can join us online to submit those Q&A to us.
We have a team of folks in the back that are going to be answering questions in real time. So some of you who have already submitted questions might see answers on them, but if we don’t get to them online, we’ll get to them at some point through the day.
This afternoon after lunch, we’re going to have a panel here. We’re going to take some of those best questions that you all have sent to us, and we’re going to answer them and discuss them together. The next session is all about efficiency. When you encounter a battery life or a thermal problem, it can be intimidating to know where to start. Fortunately, Adenine from the power team is here to help us think about how to break these problems down and make efficiency a reality for your applications. Here’s Adenine.
Go with the flow: Investigate power issues
Thanks, Phil. Hi, my name is Adenine. I’m a power engineer at Apple. Today, I’ll discuss how to effectively optimize your app’s efficiency by breaking down problems into subsystems. Doing this helps you understand how power is being used, so you can focus on where to make improvements. To do this, I’ll talk about why you should care about your app’s efficiency, how to understand it in terms of power, a couple of key subsystems, and closing with practical example. I’ll start with motivation.
You might have come to this session for a bunch of different reasons. Maybe Xcode Organizer indicates that your app is using more battery than your peers. Or perhaps you’re looking to ensure that your app supports the widest possible mix of devices. Maybe users are giving you feedback that your app causes their devices to heat up or use a lot of battery. These are all great reasons to focus on power. Fortunately, this is a solvable problem. You have a lot of levers to improve the efficiency of your app.
There’s two different types of problems you should focus on: thermals and battery usage. Thermals are the temperature of the device. If someone’s device gets warm while using your app, that can be unexpected, making your app’s experience less appealing. If the device gets too warm, the system will throttle performance in order to control temperature. That reduces the speed of your app, and in some extreme cases, it can even shut off non-essential functions until the device cools.
Battery usage, on the other hand, is different. When your app uses a lot of battery, it leaves people with less time to use it, and an overly large amount of battery usage can be a shock to users, reflecting poorly on your app and leaving a bad taste in their mouth. People can see the amount of battery your app uses day to day in Battery settings and may respond to outsized usage by using your app less often.
Your app using battery or making the device warm are actually two sides of the same coin. They’re the types of problems which can occur when power is not managed efficiently in your app. Power is the rate at which energy is used and work is done. A thermal issue can occur when an app uses a lot of power, even over a relatively short period of time.
Think of thermals as being the product of your app’s maximum power draw. On the other hand, battery usage comes from using excess power over time. Even a relatively small amount of excess power can make a big difference if it’s sustained for a long time. The cumulative energy impact can add up to a meaningful change on battery life.
Battery usage is primarily driven by your app’s average and floor power use. The worst-case scenario is when your app has high power draw over an extended period of time. The high power creates thermal issues, and the time involved can create high battery usage. So there are two goals: reduce peak power to decrease the likelihood of thermal issues, and reduce average power draw over time to decrease battery usage. A lot of the times, this work in practice means finding a balance between theoretical quality and power.
So what uses power? Literally everything. Nothing your app does is free. When an app uses device capabilities such as storage, audio, or graphics, it requires support through a network of other software on the system, all of which have to ultimately run on hardware, and all hardware inherently draws power.
Even seemingly trivial APIs may result in the system spinning up processes or using hardware, costing more power. For example, I want to load an image and display it to a user. This is one single line of Swift code, and yet it drives many different processes and system components. It needs to use radios to fetch the image. It needs to decode that image, send it to the GPU using Metal, and render it to the display.
This uses a lot of hardware and software, and it’s still a relatively simple example. Rendering a map using MapKit requires even more of the device. It needs to discover location using sensors and radios, fetch data about what’s nearby from the network, and drive all the same rendering technology and more, because it needs to render the map, its icons, and text.
It’s a whole lot. All of this from one single line of code. The system is actually able to account for this web of distributed power consumption. It keeps track of which app needs the work it’s doing and attributes the power used to that app. This means that when people view the battery life impact of your app in Settings, that includes the power used by the system on behalf of your app.
When thinking about what a workload is doing, it’s often useful to break it down into subsystems. Subsystems include hardware, such as the CPU or memory, as well as Apple frameworks, such as Core Location or SwiftUI. Different scenarios exercise different subsystems. Complex Metal effects drive the GPU and display, but not so much storage. Xcode and Instruments have tools which let you deeply inspect each individual subsystem, and the first step to breaking down power problems is to know what subsystems a workload exercises, so you can use the right tools for the job.
So now I’ll talk about what some of these subsystems actually are. Today, I’ll touch on a few key ones for power: the CPU, GPU, display, and location services. Starting with the CPU, an enormous part of your app’s power use comes from the CPU. It’s a subsystem which can often cause thermal issues, because it’s really easy to create bursts of expensive work, and that work can also occur at high frequency, such as every frame, which can raise the power floor of your app, increasing battery usage.
For CPU issues, a great place to start is to check out the Xcode Organizer. When an app exceeds a reasonable amount of CPU time over a short period, a backtrace and other details are collected. These get delivered to you as aggregated energy reports in the Organizer. Since these represent spikes in energy, they’re possible sources of thermal issues from your app, but they can also be sources of excess battery life impact when they occur too frequently. This should be your first stop if you’re looking to optimize your app’s battery or thermals, and the same MCP tools Shefali demoed earlier also work for energy logs.
The CPU runs your code, so some general principles of efficiency apply. When you hit some CPU issues, first consider if the work needs to be done at all. You can cache or defer expensive computations. Avoid work which isn’t relevant to the current app experience, and do work less often if the user can’t actually notice a difference. You can consider more efficient algorithms or operate on smaller sets of data. This makes work cheaper. When you can, prefer high-level frameworks which suit your needs. For example, AVKit is really heavily optimized for rendering video, and you should probably prefer it over reimplementing video playback in Metal.
The CPU is also a useful subsystem to examine, because it provides you hints about what the device is doing at a given time. Since the CPU manages a response to all other subsystems, requests for work will often be reflected in call stacks. This can give you really valuable hints. In Instruments, the Time Profiler track gives you insight into what your app is doing in a given scenario, even if the CPU isn’t ultimately the primary source of excess power usage. Often enough, it provides really valuable hints to what actually is.
Next, I’ll discuss the GPU. For those of you who use Metal directly in your app, you have a lot of optimization opportunities. Metal gives you so much control around that, and optimizing for the GPU work is a little bit different than optimizing CPU work. Often, the concern isn’t just about reducing power. Your app or game also has to meet its frame deadlines. Fortunately, in most other cases, performance and power are really aligned on the CPU. So by making your experience faster and able to run on more devices, you’ll usually also be using less power in the process.
When doing advanced rendering or GPU compute work in your app, there’s a lot of tools and techniques to optimize, too many to cover in this session, unfortunately. A great starting place would be to check out the documentation on “Improving your game’s graphics performance and settings” and the Metal debugger.
Now I’ll talk about the display on iPhone. ProMotion displays vary power consumption based on what’s actually being put on screen. ProMotion displays are capable of dynamically switching between frame rates up to 120 frames per second on supported devices. When content updates less frequently, iPhone adapts to a lower frame rate, which uses less power. This also lets your app skip expensive render work on the CPU, GPU, and other subsystems.
If you’re using UIKit, SwiftUI, or other Apple frameworks, you mostly don’t have to worry about this at all. The system will handle it for you. But in some cases, your app can overspecify its frame rate. This causes the system to update the display more often than it needs to, with no benefit to the user.
I’ve created an animation for my app. It has several constituent parts: a haze, pulse, and some particles. But none of these effects are actually moving that quickly. For an animation like this, a lower frame rate can be just as effective as a higher frame rate. So by reducing the frame rate, I can save a lot of power without any perceived quality loss.
This is really dependent on the effect itself and even the environment around it. For example, on this huge screen, it might genuinely need to run at a higher frame rate, so not all animations will be able to take advantage of this without compromising visual quality. So you should evaluate what makes sense in your app on a case-by-case basis.
The API you can use to specify frame rate is CAFrameRateRange. This API lets you specify a minimum, maximum, and preferred frame rate for a given effect, and the system will choose a real frame rate based on it and the other things happening on the system. In most cases, you don’t need to specify a frame rate at all. You can use CAFrameRateRange.default or otherwise defer to normal behavior. In these cases, the system will automatically detect an appropriate frame rate.
For cases where the animation is slower or smaller, you can consider lower frame rate, such as 24, 30, or 48 frames per second, if that meets your visual quality goals. Reserve 120 frames per second for large and high-impact animations, even if the animation is really cheap to render. Reducing the frame rate can save a ton of power due to how much work the system is able to skip.
Another source of power consumption in the display is luminance, or how bright the screen is. Generally speaking, darker pixels are cheaper to display than brighter pixels, especially in HDR content. An easy way to get a power win is to support Dark Mode. It’s an important accessibility option, and for some, it will use slightly less power.
For those of you that render your own content, make sure you’re only using HDR backing surfaces for content that’s actually HDR. MetricKit can also give you data about this. You can estimate the impact of the display’s luminance through the AveragePixelLuminance metric, and you can use the Display and Frame Lifetimes Instruments tracks to understand how often the app is updating the display.
Finally, I’ll discuss how discovering location impacts power. Location can be one of the most important subsystems to examine for power. When your app uses location, the device may have to turn on many different sensors, radios, and software systems. Starting all of this up and keeping it running costs power.
In addition, the system and your app both need to run to create and respond to location updates. This runtime and processing work adds to your power floor, even if you’ve optimized your code really well. There are baseline costs to continuously discovering location, which can result in really large battery life impact.
When using location services, there’s a few things which can help power. First, reduce how much location work is needed by avoiding continuous location tracking. This is the most critical thing you can do for power. Where possible, you can instead use region monitoring. If you just need to know when someone enters or exits a region, you can use the CLMonitor API. This lets the system automatically avoid location updates when the device is far away from a boundary.
But some devices or some features really do need continuous location tracking, for example, turn-by-turn navigation. A good technique in these scenarios is to defer updates when the device is stationary. If you’re using the CLLocationUpdate API, the stationary flag indicates that the user isn’t moving right now, and you can safely defer updates. These techniques let you build many location-based features without paying the cost of continuous monitoring and processing.
Background location features should be a specific point of focus, because they can very quickly use a ton of power. To get a better understanding of the cost of the location subsystem, you can use the Location Energy Model instrument, which is automatically loaded in the Power Profiler to measure power in the background. You can also use the Power Profiler in Instruments or on device.
Earlier, Cole discussed taking on-device traces for performance analysis, and you can do the same for power to profile your app’s power on device. First, enable Developer Mode and navigate to Developer settings, then Performance Trace. Make sure your app is in the list of monitored apps, and choose the Power Profiler tracing mode.
Then use Control Center to start and stop recording a trace. Power Profiler traces can be left running for several hours, really useful for tracking down those hard-to-find power problems. The resulting file can be opened in Instruments, just like any other trace. So far, I’ve discussed how to break down and introspect some of the subsystems apps rely on to understand their power consumption.
Now I’ll walk through what this kind of analysis actually looks like in practice, using an example from an app I’m working on. I make an app which is social media for cats. It lets people upload videos and pictures of their babies being cute, customize their cat avatar, and comment in character of their cats.
On today, National Cat Day, people will obviously spend a lot of time on this app, but I’ve noticed that long sessions use more battery life than I would really hope they would. As a first step, I’ll check Xcode Organizer. In this case, on my latest app, version 6.7, the Organizer doesn’t have any energy reports.
This is a great hint. It could indicate that the problem isn’t due to short bursts of power, but instead, long-running power elevation. So my next step is to profile my app’s power directly. In this case, I want to understand system power. So I’ll start with the Power Profiler Instruments template.
In addition to power, it includes some instruments to get a broad view of system activity. I’ll adjust the instruments to be more tailored to the subsystems my app actually uses. In this scenario I’m profiling, the main task is video rendering. This involves UI work and the display. So I’ll add the Display instrument to get an idea of how often the content is rendered on screen.
I’ll also keep the Network Connections instrument, since the content is fetched over the network. My app uses AVKit to render video, and I’m not doing any custom Metal post-processing, so I’ll remove the Metal Performance Overview. Finally, nothing in my app uses location at all, so I can remove the Location Energy Model.
Using that set of instruments, I’ll record a trace and investigate what’s happening step by step. First, looking at the Power Profiler overview, the average CPU impact is 2.2, GPU impact is 1, and display impact is 4. These numbers really don’t mean much to me right now, but they’re really important for comparison after I’ve made a change. We need to make sure it was actually a good one.
Next, in the Time Profiler track, Instruments indicates that the app CPU usage is pretty reasonable, around 10 to 30%. So the issue is probably coming from a different subsystem. In the Network Connections instrument, there isn’t much activity from my app. This is a hint that the networking also isn’t the cause of my elevated power.
In the Display instrument, it indicates that the duration of swap surfaces hovers around 8.3 milliseconds. That indicates that the display is updating at 120 frames per second. That’s a bit spooky. I know my app’s videos actually run 30 frames per second. So I’ll focus on what’s actually updating the screen.
Xcode has a debugging tool called Flash Updated Regions, which colors the parts of the screen which are updating yellow. You can access it by going to Debug, View Debugging, Rendering, Flash Updated Regions. In this app, the yellow regions appear over and around the cat avatar’s tail. Note that right now, video is paused, and Liquid Glass would only update if the content under and around it change, so the tail animation must be causing the high frame rate.
Reviewing my code, this is because I’ve set my CADisplayLink’s preferredFrameRateRange to request 120 frames per second. The fix here is to make the animation’s frame rate match the video’s, so I’ll go ahead and create a new helper method, getVideoFrameRateRange. This method gets the frame rate of the video and returns an appropriate CAFrameRateRange based on it. It corrects the current issue, and it makes it forward-compatible if I ever change the video frame rate in the future.
Now, when I collect a new trace with this fix, the Display instrument no longer indicates that the display is running at 120 frames per second. Instead, it shows it updating around about 30. The Power Profiler track also indicates that total power is lower, with the average CPU impact going from 2.2 to 1.3, GPU impact going from 1 to 0.1, and display impact going from 4 to 2. There are a few takeaways from this example. First, breaking down the problem into subsystems allowed me to select the right tools, narrow down the problem, and make an important power improvement.
Second, this is an example of the balance between theoretical quality and power. For some animations, reducing frame rate would be an unacceptable visual compromise. But for a small animation like this, which is already placed on top of low-frame-rate video, it’s just as effective at a lower frame rate. The viewer, when done right, cannot tell a difference if the frame rate is high or low.
These kinds of optimizations, which reduce theoretical quality with no experience impact, are often the most valuable for power. I’ve covered a lot today. Moving forward, please think deeply about all the different workloads in your app. Break them down into the subsystems they’re driving, and think about which parts are core to your app’s user experience and which ones really aren’t pulling their weight power-wise. Approaching problems like this will make you more effective at optimizing your app’s efficiency and power. Thank you.
Amazing. Thanks, Adenine. National Cat Day, I had no idea. One of the best ways to get the best performance out of your app for SwiftUI and other UI frameworks is to follow those frameworks’ best practices and techniques. And occasionally, those are a bit nebulous or hard to find. So please help me welcome Luca from the SwiftUI team, who’s going to talk to you about these best practices in the context of agentic coding. Thank you.
Build with the SwiftUI Specialist
Hi, and welcome. My name is Luca, and I work on UI frameworks. Xcode 27 ships with a set of agent skills to support you in building the best app. A skill is a set of instructions and reference material that provides an AI agent with specialized knowledge. Skills can be automatically loaded if they are considered relevant for your prompt, but you can also explicitly invoke them by name.
In this talk, I want to focus on the SwiftUI specialist skill. SwiftUI is designed to provide a delightful developer experience, leveraging the Swift language and abstracting away complexity to let you build great app. And this skill is a natural extension of this goal. I love SwiftUI, but do you know what I really love?
Well, that’s croissant. So I know, I know, San Francisco has some amazing pastry, so I recently took my team on a tasting tour to try the best one. But obviously, every time we leave the office to do something fun, there is one extra thing that always end up happening. Someone on the team has to make an app for it.
This time, it was my colleague Steven’s time to shine, and he’s been working on an app to track and rate all the best pastry we tried. But I’m not sure if the app is done yet. He just sent me a video voicemail, and I wonder what that says.
Hey, Luca. So I’ve been working on the app, and I have a couple of updates to share with you. First, I was doing some performance profiling on the list of pastries, and I noticed that the cells seemed to be updating more often than they should. Second, I had a great idea to add an entirely new tab to the app. It has a map view, and it shows where all of the bakeries are located. I know, I know, scope creep. But I got it done really quickly. The only thing is, I was in a hurry, so I may have cut a few corners.
Anyway, I would love to be able to look at these things, but I’m going on vacation now. So I was wondering, could you please do me a favor and take a look at them? I promise to bring you back a souvenir. I don’t want to spoil anything, but I hope you like magnets. Anyway, thanks. Gotta go. Bye.
Oh, boy. I know it looks like I have my work cut out for me, but let’s take this one step at a time. There is three things I need to do. I need to understand this codebase first. Then I’ll dig in and fix the update issue that Steven wants my help with, and then review the new tab with the maps. I’ll start by opening Xcode and explore the project that he sent me.
Okay, so PastriesTrackerApp is the main entry point for the app, and on the right-hand side, you can observe a preview of the app main screen. It shows two tabs, but let’s focus on the first one for now, where we have a list of tastings, with the pastry I’ve tried, where and when I tried, and a rating for each pastry.
Finally, up top in the navigation bar, I have a button to add a new tasting. Now I want to start by familiarizing myself with the code. Agents are a great way to start exploring a new codebase. I’m going to show you how I usually use them for this purpose. In Xcode, I’m going to start a conversation with the agent by selecting the Coding Assistant button in the toolbar and clicking on New Conversation.
In the prompt field, I’m going to ask the agent to help me understand the project. So I’m just going to type that. I want to understand this project. And I’m going to ask you to make a table, starting with the data layer. And also add a very brief overview.
This is actually how I generally like to start understanding an app. I always prefer starting from the data layer, because in my head, I start picturing the data relationship and operations that are possible. And from that, I can build up how the UI looks like and how it connects to data.
This is very powerful to me, because especially in SwiftUI apps, understanding of your input and how they cause UI to update is fundamental to working with the framework. I’m choosing to have the output as a table, because it makes it easy for me to scan the output. Okay, I think we have a bit of a problem here with Xcode. So, you know, you know that this is live. So let me try to close Xcode for a second and see if something works out. One second.
But that’s the fun of it. Okay. Let me… All right. Okay. Let’s see. We should be back. Let me try again one more time. So… Yeah. So I’m going to go back one second and just run you through the prompt again that I want. This project. And I’m going to ask you to make a table.
And again, ask to make a brief overview. Let’s see if now it’s working. Yeah. It seems that now… Yeah. You can see on screen that it’s finally writing. Yeah. All right. Cool. We have our table right here. Okay. So the agent finally finished. We needed to, you know, try again.
But in the transcript, you can see a summary of the data type in this project. So let me walk you through the most important one. We have Tasting. And this is the type that represents a tasting for a specific pastry at a location. This is the data type that is backing a single row. And this Tasting has a couple of nested type for coordinate and rating.
But the more interesting type here seems to be TastingStore. This is the observable type, which holds on to the list of tastings and exposes that to the view. So now I want to learn how TastingStore is being used and understand how the data flow through the UI. This gives me a starting point to investigate issue with view updates. So I’ll navigate to that file. In Xcode, I’m going to use the Command-Shift-O keyboard shortcut to quickly open a file. And I’m just going to type in the symbol, so TastingStore.
And here we are. That’s the store type. So okay, now stick with me as I do some keyboard yoga. I’m going to use the keyboard shortcut Command-Option-Control-Shift-H. Yeah. I practiced this many times. Yes. And this opens a new conversation in a side pane. And I’ll type in my prompt to ask how the store is being used. So I’m just going to ask it to tell me how this is being used in a view and what view is observing this data.
Right. So when I make this more specific prompt, I like to keep the code editor and the agent side by side so I can glance at the source while the agent is working. And then I can look at the responses and navigate around the code. While the agent is working, let me point out the tastings array.
That’s the data that the app is going to display in the list. The agent has finished, and there’s quite a lot of context. Let me actually scroll up a little bit to see the beginning of it. So let me just highlight the most important point. So TastingList is the view that observes the store. And that seems like a good next step for our investigation. So I quickly take a look at TastingList. I’m going to use again the Quick Open keyboard shortcut and navigate to TastingList.
Okay, so the view iterates over the tastings coming from the store to generate a list where each row gets a tasting. And Steven told me that he noticed that the cell row was updating more than it should be. So I’ll use the agent to figure out why this is happening and if there is anything I can do about it. So I’m going to continue this conversation and just state the problem. The cell row is updating too frequently. And just look into a fix for it.
All right. So this prompt asks if there is any improvement to either Tasting or TastingStore, because updates are caused by changes in the input to the view, and also explicitly asking the agent to focus on view updates. Making sure that Observable notifies the view only when something has changed is a good first step for this investigation. Note also how in the transcript, it shows that the SwiftUI specialist skill is being activated.
Using the agent with this skill is like sitting with a UI framework engineer, working together to build apps that follow modern practices. The agent has finished producing the answer, so let me highlight the most important part. And I need to scroll up a little bit again. There we are. So the agent is telling me that the main issue is that Tasting is not Equatable. An Observable type does not constrain its property to be Equatable.
But if you make the type of your property Equatable, Observable will avoid updating a view if a new value of a property is equal to the previous one, and the agent is also suggesting a fix for this. All of the properties are already Equatable, so you can just add a conformance to it. I’m going to ask for that fix. Just ask him to add the conformance for that fix. So I’m just going to type in, “Yes, add the conformance to Equatable.”
Cool. In the transcript, there is a rich representation of what the model is doing, and it really helps me get a sense of what’s happening when it’s reading the file, then making an edit and finally compiling the project. I also really like that when the agent produces some edit, it shows the diff in a new panel. And also, a little tip: I can hover over any line number to leave an inline comment if I want some additional changes or just clarification.
So I just made the Tasting type Equatable. This is the type that is being used by one of the properties of my observable type. But this skill is great for asking clarifying questions about your code or how SwiftUI works. For example, if I want to know whether there is any benefit to making the model object Equatable, I could just ask that. So let me ask that again to the agent and just give myself a little bit more space right here and ask if I should make TastingStore Equatable. And I’m going to also ask if this helps reducing the number of update.
So the skill is designed to provide explanation for all the recommendations and guidelines present in the skill. And you can use it as a tool to support you in learning and understanding, even when most of the code is written by AI. Understanding is fundamental to collaborating with the agent and verifying its work.
The agent has finished. I’m going to scroll up a little bit again. And it’s telling us that there is no need to make the observable type Equatable, because the view update is not driven by the equality check, but instead by the signal sent by the Observable conformance. Now, this investigation was fairly targeted to a specific type where I knew that something was not quite working. But this skill is also great for doing broader analysis and review of your codebase.
The second thing that Steven told me about is this new map view, and Steven didn’t seem very confident about the way it turned out. So that seems like a great opportunity to use the coding assistant to check it out. I’m going to start a new conversation so I can give the agent a fresh new context.
And I’m going to ask it to take a look at all the views related to the map view. I’m going to ask to review for best practices and opportunity to modernize. And finally, I’m going to ask it to propose a list of all the improvements and work through them one by one.
So note that in my prompt, I’m explicitly asking the agent to focus on the map view of the app. And in general, I will not recommend using a single prompt to review the whole codebase for larger codebases. These can quickly fill up the agent context window, and this degrade its capabilities. But more importantly, it can become too overwhelming on you.
And another tip is that I really like to ask the agent to also work on suggestion one at a time. I do find intimidating to stare at a big wall of text with a laundry list of issues that I need to act on, and instead, I prefer to get a summary first to ground myself and then work through all the suggestions one by one in order of importance. This is a great way for me to better understand and trust the changes that the agent makes to my code. And honestly, making some changes and verify that it works as I expected is a very fun and effective way to learn more about new area of codebase.
Okay, the agent is finished. I’m going to scroll back up again to see the beginning of all the proposed improvement. And we can see here a list of improvements. And they’re all grouped into multiple categories, like localization, best practices, accessibility, and more. I like these, because it makes it easy for me to understand their priority and importance. And I also think it’s great that the agent has a sense of what are the most important areas in SwiftUI apps and the highest-impact changes.
And as you might guess from my accent, having an app that is well-behaved across locales is important to me. So I’ll ask the agent to implement the first fix, which is a change to better support localization. I’ll come back to this later and review it. So I’m just going to type in, “Yes.” All right. Cool.
Okay. So I just demonstrated how you can use the SwiftUI specialist skill for targeted fix to your code, building a better understanding of how SwiftUI works so that you maximize your leverage with this very powerful agent, and finally, how you can use this skill as your own personal SwiftUI engineer, continuously supporting you in evolving and improving your app.
But this is just one of the several skills available in Xcode for working with UI frameworks. There is also a great adaptability skill that allow you to easily get your app layout ready for iPhone Duo. We have a “What’s new in SwiftUI 27” that describes new API behavior and deprecation in the framework. This skill is a great way to bridge the gap between model training and the current SwiftUI APIs, but it’s also a great way for you to learn what’s new.
And also, there is a skill to help you build document-based app, which contains information about all the new API, like ReferenceFileDocument and how to adopt that in your app. And beyond the skill for UI frameworks, we also have skills covering other areas, like App Intents, security, and testing. Throughout the talk, I’ve used the Coding Assistant feature in Xcode, which comes with this skill package, but we built them to be used with any coding agent of your choice. You can run this xcrun command to export all the available skills and add them to your agent.
So this is an overview of the SwiftUI specialist skill. It’s available in Xcode 27, so go try it out on your project. Let it review specific area of your codebase for best practices and recommendation as you write new code. This skill will work with you to build high-quality SwiftUI apps. This skill synthesize our experience working with all of you. So please send us feedback so that we can continuously improving it and make it another important part of the way you build apps. Thank you very much.
Thank you, Luca. That was great. Okay, before we break for lunch, I want to talk about this afternoon’s activities. For those of you online, join us back here at 1:30 p.m. Pacific on the stream. We’ll have a panel to discuss many of the performance questions you’ve been asking over the course of the day. For those of us in person, you can pick up what you’d like to do from now.
From 1:30 to 2:30 p.m., you can come back here to Big Sur and join the audience for a live Q&A with a panel of engineers. But if you’re here in person, you can also take advantage of the engineering labs that we’re going to be having going on the rest of the afternoon.
In person, there are 40 Apple engineers who specialize in different areas of power, performance, and other topics to answer your questions. There will be three lab areas in the building. Follow the signs right outside to find the ones that work for you on both floors. There are going to be general labs for performance topics.
You can think of these as a catch-all bucket for any performance questions you might have that might not be specific to any other lab. On the first floor, there are going to be topics and lab areas for Xcode and Instruments, hangs, hitches, animation hitches, and memory. On the second floor, we’re going to have labs for persistence, power, and SwiftUI.
If you’d like to chat with somebody, just walk up to the lab area. Find the person wearing the red hello shirt in that lab area, and they’ll help you find the best engineer you can speak with. The labs will be running from 1:30 p.m. through the end of the day.
There’s no need to rush, even if the area looks busy at first, which I’m hoping it will be. We’ll have plenty of time to get to your questions. Thank you so much for joining us this afternoon and this morning. For those of you who are joining the Q&A later, we’ll be back here at 1:30 p.m. Pacific Time. Thank you.
Power and performance Q&A
So again, my name is Cole. I’m a technology evangelist here at Apple. Welcome to the Power and Performance Q&A. I’m excited to welcome our panel to chat through some of the questions that you all submitted online and here in person throughout today’s event. If you have code-specific questions, or somehow we don’t get to your question today, I encourage you to bring your questions to the Apple Developer Forums at developer.apple.com/forums. If you also have a bug or a feature request, you can also submit that to us through Feedback Assistant at feedbackassistant.apple.com. And so now I’d like to welcome to the stage Phil, Shefali, Adenine, Luca, and Steven.
Hey, folks. Welcome to the stage. Thank you. All right. Maybe we can start off with just a round of introductions. I know many of you were on stage earlier. Hey, Steven. Nice to see you. Yeah, let’s just start with some intros. So I’m Steven. I work on the UI frameworks team.
I’m Luca. I also work on UI frameworks. My name is Adenine. I work on power. I’m Shefali. I work on third-party performance tools. And I’m Phil. I work on performance engineering. Great. So thanks for spending some time with us today. Steven, it’s nice to see you. You weren’t here with us on stage, but we kind of saw you deliver a video voicemail to Luca earlier. How was your vacation? Actually, I didn’t forget my promise.
All right. There we go. There it is. It was very good. Thank you for asking. That’s awesome. So maybe Steven and Luca, let’s just start. I see some questions here about the SwiftUI skill. I’m wondering, maybe we can just start with some background about kind of what motivated the SwiftUI team, you folks in particular, to build the skill. And what are your goals in kind of putting this out into the world and in Xcode with this skill?
So yeah, I would say the main goal was kind of giving all developers this feeling of having a UI framework engineer sitting next to them when they’re working on their code, writing new code or reviewing their existing code. So having an expert sitting next to them, helping them writing correct code.
And also, there’s this interesting gap between the training of the model and what actually is the latest API, the latest recommendation. One example that comes to mind is that in iOS 27 and aligned releases, we made @State a macro instead of a property wrapper. So there are some small incompatibilities with that.
And as part of the “What’s new in SwiftUI 27,” we have instructions for the agent on some compiler error that it might encounter and how to fix that. So they function as this bleeding-edge knowledge of SwiftUI, of what are best practices and what are the latest API that we are releasing and how to use them.
Yeah, I really like getting to come to these events and sit one-on-one in labs with all of you. Lots of little hidden gem-type things come up all the time, especially when looking at things like performance that are sort of very specific things for specific situations. And so if you actually go and read the skill content, there’s a lot of stuff that I would call deep cuts.
And I get really excited about that. And so I really wanted the experience to feel a little bit like getting to sit down with us and kind of have that lab experience, even if you can’t be here. And actually, the command exports the skill. Go read the skill. There’s a lot of interesting tidbits. We try to explain every recommendation that we give, what is the motivation. And you can really learn a lot from just reading the skill.
Yeah, I also noticed, Luca, you kind of mentioned that the skill can activate on its own, but you can also ask for it explicitly. What is your expectation of what people should expect? Is that something that they should do? Is the expectation that it should automatically activate if you’re giving it a relevant task? What’s your kind of intent there? Yeah. So I think the expectation is that it should activate by itself.
The activation is based on the prompt. And so if you’re asking specifically about best practices, reviewing the code, or writing modern SwiftUI code, it should automatically be running. But you can also simply invoke that if you know that that’s what you need from the agent. You can just invoke the skill and ask directly to kind of work with you.
I will also say that some models are more confident than others, and occasionally, they’ll think, I know the new thing, I don’t need to activate the skill. And so thankfully, in Xcode, and actually a lot of the agent harnesses, it tells you when a skill gets activated. And so if you want to make sure that best practices are being followed for new SwiftUI code that’s being generated, just asking your agent to use the skill to check the best practices can also be really helpful.
- Yeah.
- Totally. I’m going to pivot to a bit of a different topic. This one might be for maybe Phil and Shefali. Earlier this morning, Phil, you actually had some quotes from Notion and Tinder about some of the work that they’ve done. And what I thought was interesting is the things that the developers are pointing out is that it doesn’t just make a better product and that it feels better to use, but it has business outcomes that they’re starting to measure.
And there’s a question here. I’ll kind of paraphrase it, but what they’re kind of interested in is, first of all, does Apple have anything that can help developers kind of draw a line between this kind of performance improvement to dollars or some sort of business outcome? So does Apple provide anything like that? And on top of that, if you need to build something to do that, what does that look like? Yeah.
I think it’s an interesting thing, because I think a lot of us, when we think about performance engineering as a sort of vertical of software engineering, we think about a quality area. And really, the app’s quality is something that dictates… At least what we’ve seen from the data that we’ve captured is that app quality and retention are really closely tied together.
And I think when you try to figure out, or when you try to plan for, how do I measure whether a performance change or performance improvement is worth the squeeze, one of the areas that you might reach for is, oh, can I check my retention metrics or my engagement metrics, how long people spend on certain screens or how long they spend in certain features?
Apple does provide direct business metrics in App Store Connect. You can actually look at some of the direct, how much money did I make from this thing, or what’s my churn, or other kinds of metrics within App Store Connect. And we also provide facilities for you to compare them against apps that are your peers.
They’re called peer group benchmarks. And fundamentally, those metrics, while they’re not necessarily tied to app versions, you can really easily draw the line between, hey, I had a major architectural change in an app version that I released, and I saw a big shift in my, sort of, what I’ll call business metrics.
And it’s the first thing that I… If I were to recommend anybody now in the age of AI to think about performance, the first thing I would think about is how do you use and leverage AI to make your performance as good as possible, make your quality as good as possible, so you can really just focus on tracking metrics like retention and engagement, churn, things that are really more customer- and product-centric, versus how do I make the hang rate go down, or how do I make the battery usage go down, as sort of the indicator of quality.
And Shefali also mentioned in MetricKit, for example, if you’re collecting the raw data from MetricKit, you can kind of use StateReporting to break metrics into different feature areas or different areas of responsibility among the development team. So how does MetricKit fall into this, right? If you’re starting to kind of figure out how to do the data science and draw the line to business outcomes, you might turn to MetricKit to get some of that data. How should you kind of get started with that? What’s the right way to think about that data and your business outcomes?
Yeah. I mean, like Phil said, we have the peer group benchmarks in the App Store Connect API that tracks all of these business metrics, and you can use things like StateReporting to track new features that you’re adding, or just how people are using your app overall, to figure out if that usage then somehow correlates with these business metrics, especially if you’re releasing new functionality or new features within your app.
And so MetricKit provides you with that ability to slice and dice in different verticals and different directions so that you can get that holistic picture of, did I do something that has moved the needle recently to the point on peer group benchmarks? We also, through the Xcode Organizer, provide these recommendations around app metrics for developers to look at where they can see their app metrics and if people who are part of this similar app group have exceeded or done better than them in a given metric. And so it gives them something to strive towards. Yeah. So I want to talk a bit about those goals, because I find this concept really interesting.
From one lens, it’s like if you have hangs in your app, that’s bad, right? But the Organizer doesn’t say you should have no hangs in your app. It says, based on similar apps, you should have this hang rate. Can you just talk about kind of the philosophy there? Why is it giving a goal that is not perfect? What’s the thinking there?
I think that given everything else that’s happening on your device, and I think I alluded to this during my talk as well, given everything that happens on the device, it’s really hard to achieve that zero-hang mark. And there’s always going to be something that inadvertently blocked the main thread for a period of time and caused a hang. But these peer group, or peer-based, recommendations tell you, based on other apps that are similar to yours, how are they doing with hangs? So what’s actually achievable, given the functionality of your app and the app category it falls into?
So you’re not striving for perfect. You’re striving for the norm, right? Yeah. Do you have anything to add, Phil? Yeah, I would add that I think Shefali said it very crisply here, is that I think perfect is kind of impossible in performance. You don’t control cellular networks, you don’t control the weather and how hot it is outside when somebody is using a device. And you certainly don’t control all the other things that they’re doing on their device outside of using your application.
So I think it’s really difficult to achieve a state where you don’t have performance problems. But I think it’s very achievable to reach a state where the look and the feel of your app is good enough, where users don’t really notice or care about the small hiccups. Yeah, and the peer group benchmarks help just set the context of, if you’re, let’s say, a video player, and you have a lot of other video players, you’re competing against that. If you have a hang rate of a certain amount, maybe that’s just the baseline experience that people have when they use these types of apps.
Now, in the future, when you can use AI to accelerate all of this, maybe it’ll be a little bit of a different conversation, but I think it’s better to help your teams and your agents focus on getting to a place where the performance feels like it’s good enough, and then you can shift focus to things like building the next innovative feature that will bring more people to your app, or helping people find time to go and re-architect things that maybe weren’t architected the right way to begin with.
Because really, the worst thing is if your… And we’ll use hangs in this example. If your hangs are so prominent that someone stops using your app, and that will then directly result in your retention metrics. So making sure that your app performs in a way that’s smooth is really the goal. Yep. Yeah. Phil and Shefali, you both mentioned AI, and I see some questions here coming in about the skills and the tools like xctrace that you talked about earlier.
I think I see a couple questions that are all around the same lines. But it seems like people are interested in knowing if the tools and the skills that we talked about today… We, of course, showed them in Xcode, because we think that’s the best place to use coding agents. But is there anything that folks might be missing out on that we talked about today, or doing performance work if they’re maybe using external agents or not using Xcode?
I… I don’t… Was that just directed at the group? That’s directed to the group. Anyone that wants to answer that one. Practically, no. I think realistically, all the, especially the skills bundles, for example, can be exported, and the tools, and Generate Recommendations, are accessible via MCP. And xctrace is a CLI.
I think practically, no. I think you can… Obviously, we would love for you to use Xcode, and we think it’s the best place to use agents for Apple platform development. But I do think that realistically, we know everybody’s going to be using a lot of things. So we put a lot of intention in making sure that the tools that we build can be used outside of the context of Xcode.
I am a big fan of some of the little UI things inside the coding assistant, actually. I didn’t realize, I think Luca mentioned in his talk that you can add inline comments. And when I saw him rehearsing that, I had no idea that that was a thing that you could do.
And I thought that that was really cool. I also really like the way that our transcript kind of explains to you all of the things that it’s doing with color coding. I think it probably varies from agent harness to agent harness, how much of that information you get.
And I think one of the other things that I like in Xcode is it’s relatively easy to switch back and forth between models from different providers without switching harnesses. I know there are tools that let you do that externally, but there’s something nice about that integration when comparing results that I really like. And there’s also just a question about xctrace specifically. Sounds like, of course, today you showed us how xctrace triage and xctrace show solved your hang, which was awesome. Do these tools work for more than just hangs?
Yeah. So triage is… We saw obviously the example with hangs, but show really works for everything else. You can throw it at a performance issue that you’re seeing, and I encourage you to do that, because it really should be able to take a trace that you have and really be able to understand what is going on from a performance perspective.
Awesome. Just looking at some questions here. Please keep them coming in. I can see them popping in here as you folks submit them. I think one of the other areas that we’re getting questions about is around automated testing. I think one of the questions that we had was, let’s say you’re using xctrace triage, like you showed. You want to put the agent in a loop to verify its own fix.
You probably don’t want to do that in the simulator, but you do kind of maybe want to have some sort of automated testing for performance and maybe use tools like that as part of that. Do you folks have any kind of just thoughts or best practices on how you go about automated testing for performance if you’re not going to use the simulator, like you suggested?
I mean, I think the key is a physical device, right? It’s making sure that you have functionally heavy pieces of your code configured in a way where you can write and run performance tests around them. And I said this during my talk too, but a model can greatly help with that. An agent can help with that, and making sure that you’re taking that extra step to test those individual areas in conditions that are not just at your desk, near your modem, where the throughput is going to be the highest. Yeah, yeah.
I think there’s… I mean, I know that we’ve talked a little bit about simulators not being the best place to do this. But I think, practically speaking, a lot of us don’t have the ability to set up device farms and have tons of physical devices with cables and people that manage those and restart them and whatever. And I think simulators are a great step when you’re looking for a directional guidance, right?
And a simulator may not tell you, oh, this is the physical amount of, let’s say, energy that you’ve drained, or this is the physical amount of storage you’ve used, or something like that. But the simulator will tell you, hey, from A to B, maybe you did objectively, absolutely, more work.
Right? And that sometimes is a really good starting point for most of these agent tools and harnesses to be able to kind of go and start finding things to optimize on their own. And when we talk about loops, really, that’s what we’re looking for, right? It’s self-iteration, finding things on its own, and then eventually converging a feature to a point where it’s good enough.
So I wouldn’t say don’t use simulators, but I would say use them in a way that first leverages xctrace and some sort of Instruments, which is designed around measuring performance on our platforms. But then also use it as a way to find directionality, not accuracy and sort of absolute physical reality. It totally makes sense. I’m going to switch gears a little bit. I see some questions about power. So I’m going to turn it over to you, Adenine.
I think there’s actually a whole bunch of questions that I think kind of come in the same area. It has to do with GPU debugging. I think the questions kind of come down to, Shefali talked about how agents might be able to inspect a trace for things like hangs on the CPU.
But today, we didn’t talk too much about how an agent might be able to do some sort of GPU debugging. Do you have any recommendations or thoughts there? Yeah, definitely. So whenever you’re collecting an Instruments trace, there is the Metal Performance Overview, as well as, in the Power Profiler, the average GPU impact. And those can be good starting places.
But a lot of the time, they’re potentially less information than you really need to really drill down on GPU issues, particularly if you’re having agents who maybe doesn’t have all of the context you have around a problem. And so you, as a human, might turn to the GPU debugger, which is extremely powerful, able to play back frames, and gives you an absolute ton of information.
The great thing is that there is a command, which I believe is new in Xcode 27, called GPU debug, which gives the agent a way to introspect these GPU debugger files. And this lets it understand all of the same things that you would understand out of using the GPU debugger UI.
Yeah, it’s really cool. Actually, I had my own project using Compositor Services on visionOS, and I just captured a Metal frame using the debugger, handed it to my agent, and it came up with all of the things that someone smarter than me that actually knows something about GPU debugging… Found some great stuff, so definitely a cool tool to check out.
Okay, taking a look here. We have just, since we’re talking about xctrace triage and some other things, there’s a question here. I apologize if I’m mischaracterizing the question here, but I think what they’re asking is, they’re asking about the security and privacy guarantees of xctrace triage. I think what the question may be kind of getting at is, does this triage command send the trace out to a server and provide results? Or what should people be concerned about in terms of privacy when running that tool?
Honestly, xctrace triage runs locally on your device with a local trace, so there aren’t really concerns around the data being synced off device or sent to a server somewhere. So I mean, I think the amount of trust that you put into whatever agent you’re using is really what applies here.
Totally. Yeah. Yeah. Just to add on to that, I think there’s a distinction between what you provide to the agent for inference, what you provide to the model for inference, and then what, for example, a Python script extracts out of the trace on device. And I think if you’re using an API subscription or a model subscription, or if you’re using tokens, the data retention of the data that you put into that inference is kind of between you and the model provider. And so the triage script itself is definitely happening on device. It’s kind of extracting features of the trace locally.
Phil, I have a question for you that I think you’re going to love. Great. So Phil worked a lot on MetricKit, so I’m going to give him this MetricKit question. So the question is, this developer is using Firebase Crashlytics. Maybe some of you folks are using other tools, like Sentry. And the question is, does MetricKit overlap or conflict with SDKs like this? And would you run MetricKit alongside them, or would you pick one?
Yeah, we get this question a lot. I think you have to think about it like this. Let’s use a contrived example, like Sentry, right? Sentry offers a lot more on top of just power and performance data and diagnostics than, for example, MetricKit does. MetricKit, you can think of it like a data source for something like Sentry or Firebase. It’s like… If you’re going in, tapping a tree for syrup, right?
MetricKit is the tree, essentially. You’re getting what you need from it, and then you can use that syrup any way you want. That’s a terrible analogy, but I’m kind of hungry. But, you know, so MetricKit is more of a data source, a primary data source for these tools and systems. And the way that MetricKit works fundamentally is that we have this concept of subscribers in the framework, where you kind of register for data. And there’s only one set of data that’s really provided to an app, and that’s just shared among all the subscribers.
So you could envision that something like Sentry, which is a higher-level system and sort of a more full-featured, actual product, would be one of those subscribers. And it would collect data to kind of avoid having to do a lot of in-process work for things like maybe, I don’t know, animation monitoring or error monitoring or crashes or something like that.
So I wouldn’t say that they’re duplicating work. I think MetricKit just provides a way for tools and products like this to avoid doing a lot of the work themselves in process, which, again, adds observability overhead to the app. And it adds all sorts of other emergent problems that maybe app developers wouldn’t know unless they kind of looked at the data themselves.
Yeah, I think you could definitely use them in tandem if you want. Like I said, Sentry and Firebase, they offer other types of things that are really valuable for developers, and MetricKit doesn’t. So yeah, no, totally. And many of those frameworks use MetricKit as a data source. - Yeah. - Definitely.
I have a question for Adenine. This is actually a question about something that came up in your talk. You kind of mentioned you were breaking down the different subsystems. You talked about CPU and GPU and display and location. And in the GPU section, I know we didn’t have time to talk in depth about Metal optimizations. That’s okay.
But you mentioned something that was, power and performance are usually aligned, because if you want to meet your frame deadlines, you got to do less work. And so that’s going to cut power. I’m really interested in that word, “usually.” Are there cases where that’s actually not true, and that power is something kind of to look at differently?
Yeah. So kind of taking a step back from just the GPU, power and performance are a lot of the time, on all of the subsystems, aligned. And the reason for that just intuitively is that if you’re taking less time to do something, typically, it means you’re doing less work.
And so you’re having to burn less power to do that work. Power is the rate at which work is done. The real sticking point there is “usually,” because there are all sorts of exceptions, really on a case-by-case basis for the different subsystems. And so, for example, right, let’s say you have two threads, and the one thread is waiting on something from another thread.
Well, on that one thread, you could be spinning, constantly checking it, so you’d know right when the other thread finishes. And that would be good for performance. But because that one thread is spinning, it’s going to be worse for power. Then conversely, if you’re potentially doing a messaging system, then that would be probably around about as good for performance, but better for power, because you’re not spinning.
And that’s just a very sort of simple example, but it does get to… There are these misalignments. So on GPU specifically, then, it’s interesting, because GPU is very much just, go do the compute, go fetch the data, go… It gives you a ton of really low-level control, because if you’re using Metal, you need that performance.
And so the biggest place where power and performance are misaligned on the GPU is actually frame rates. And so that, again, comes back to, well, if you’re doing more frames, you’re doing more work, you’re using more power. And so in other cases, it’s more aligned than other subsystems. Yeah, I don’t know. - Great. That makes total sense. - A little bit of a ramble. Yeah. No, thanks for elaborating on that.
I’m going to switch gears a little bit back to our SwiftUI friends. So this is a question about, Luca, something that you talked a little bit about, where Steven helpfully dumped this project on you, and then you used the agent to just understand the codebase. When it comes to using the specialist for something like this, which is an existing project, are there any differences between how you approach problems or use the skill for something like that versus, I’m going to make a brand-new app, and I want the specialist to come in and help with that?
Well, yeah. So first of all, at the beginning, when I was using the system to just discover the app, we generally don’t expect in that case for the SwiftUI specialist to be activated. It’s more kind of you use that to understand. I think, to me, the main difference is that especially when I’m trying to understand a codebase or certain decision, I can actually, again, use the skill to prompt for decisions, like, okay, is this a good decision, and why? Again, a lot of emphasis on trying to explain the recommendation that we give.
I think perhaps when you’re generating new code, it’s just, you’re fine. You get the new code, and hopefully it is with the right design, with the right best practices. So I think, I would say it can match your frame of mind. When I go and try and raise an existing project, I need to understand it. I need to create this mental model of what’s happening.
And so in that frame of mind of asking questions. And if anything, I sometimes like to ask the agent to make a change. And I validate that, oh, does this actually produce the change that I was expecting? If I change this call to happen at a later time or something like that, is that what I’m expecting to happen, versus generating new code? So yeah, I think that, to me, is the difference.
I think for new code, I think it’s important to remember that the models are a snapshot in time, and that they know certain things about SwiftUI, but we’ve observed things that they maybe don’t know about SwiftUI. And so a lot of the content in the skill is designed to be able to tell an agent how to do a good job at writing SwiftUI, based on the things that are important that we tell people out in the world and also that we tell engineers inside of Apple who are building apps in SwiftUI.
And so a good way to not run into any trouble with your new code is to just integrate the specialist as a part of that process of creating a new app, so that you don’t end up in a situation where the agent did the best job that it could, but maybe it didn’t consult the guidance that we’ve given it for best practices, because the model’s training says, I think it’s fine to put a closure in the environment.
And it doesn’t know why you shouldn’t do that. But if you read the skill content, we’re specific to explain what is the actual reason that we’re giving this guidance. And models seem to be fairly convinced by that, because they want to understand the same way that we do, I feel like, when looking at code.
I want to add something quickly that’s more not related to the SwiftUI. So, but I think what you just touched on is really important, because the longer you are on the frontier, the more that these models inherit and capture stuff like these emergent skills that we’re building. And so in a lot of ways, it’s just kind of like getting a new version of iOS, where it has this cool new feature that, when it comes out, it’s like, oh, this is new, this is interesting. I’m learning to use this. And then over time, that becomes more of second nature to us. I’m thinking, like, Control Center, when we first introduced it, was this big innovative thing, but now, we couldn’t imagine iOS without it.
And the models kind of learn very similarly, where over time, the stuff that we’re sharing in these skills will become second nature. And they’ll do these things by default. But the skills iterate and represent a way for us to kind of continue to share some of these things that maybe a UI performance engineer would only know, or these things that a power engineer would only know, as the sort of context and the knowledge evolves working on them at Apple. So I think there’s never not a good reason to pull in the latest set of these skills, right? It’s basically free context in some ways.
And also, don’t sleep on the What’s New skill. I know we talked a lot about this with UI specialists, but one of the things before that we were really interested in was what’s going to happen when somebody talks to an agent and they watch the talk about the great new APIs, like reorderable or the new swipe action stuff. Will an agent be able to answer those questions? And the answer was no. And so we wanted to make sure that we could steer them in the right direction so that you can get started with the new stuff right away. Totally, totally.
I see some questions here about some very specific SwiftUI kind of performance challenges. And I don’t want to make you try to compile some SwiftUI code in your head live on stage with a bunch of eyeballs on you. But I am curious. We do that every morning. But I am curious, can you kind of walk us through an example of, this is maybe something that folks in the past have struggled with for performance in SwiftUI, but the skill actually knows how to handle this and can do it well? Is there any kind of code pattern in SwiftUI that you think the skill will be able to help with?
The environment stuff in particular is an area that I think we’re particularly proud of, because, and I’ve given some talks about this in the past, it’s easy to end up sometimes in a situation where you’re putting frequently updating geometry into the environment, which is causing your view bodies to invalidate more than you would want them to. Or putting things… Your presentation from a couple of years ago was on that. From actually last year. - From last… - Year. Yeah, it’s the year anniversary. Time flies. Do you remember I said closures are spooky? - That was… - Yes.
So yeah. So one of the things that the skill does a really good job of is identifying scenarios like that and actually presenting you with options for what to do, because a lot of times, these things are tied into the architecture of your app. And it’s not as easy as just changing a couple of lines of code.
There might be considerations about how your model objects are structured, or where should the closure live? How often is the closure going to be updated? And we have some sort of A/B options that you can read in the skill of, when you hit this scenario, what are some things to present to the user? And it can be really good at that.
It also pairs really well with Instruments as well. The SwiftUI instrument, if you go and look through it and see that you have something that’s updating too much, if you go back to an agent and you say, hey, I think that this particular view is updating too frequently, it’s pretty good at using the skill to go and look at the code and try to help you triage what actually might be happening there.
Totally. So the recommendation on the onChange, and kind of avoiding these onChange to trigger massive update to views that are reading every possible property, and kind of trying to break that down. So even just the way you structure your code, it has an effect. And we try to kind of nudge the agent toward that. Totally.
I want to come back to Phil and Shefali. I think you’ll have some thoughts on this, although this is open to everyone, of course. Shefali, in your talk, you kind of mentioned this idea of a pipeline where even without your intervention, something could go grab data from the MCP or from MetricKit and then kind of generate fixes for you that you review and merge in. And the question here is, can you talk more about that? What would that entail? What would that look like if a developer was interested in building something like that?
Yeah. I mean, so we talked about three different data sources, right? We said there was MetricKit. We said there was the Organizer MCP tools, or the performance MCP tools that fetch data from the Xcode Organizer. And then there are the App Store Connect APIs, which are also a programmatic way to get access to your power and performance data.
And so if you have access to your data coming from your user population, and all of these tools kind of give it to you with different user populations, you’re able to then use the, let’s say, performance MCP tools to analyze that data. And what it’ll do is take the data, assess it in the context of your codebase, and tell you exactly why that issue occurred and start to make recommendations.
You could then take that recommendation, ask a model, let’s say, or an agent, to assess the impact of each of the recommendations that were made, or decide for itself which one is the best, and create implementations of each. And then you can go test it yourself or have the model put up a PR on your behalf so that you can then go review it, test it, see if you want to do something different with it, and then come back to your project.
And it’s kind of that loop that we’ve talked about of taking the data, operating on it to get to a point where you’re able to resolve it, and then test it, right? Use XCTest to actually test the performance impact of it. See if it’s gotten better by testing before and after a fix was made.
And then if you’re comfortable with the changes that were made to your project, and the functionality is still kept the same for whatever feature this agent has touched, you can put that into your project, and now you’ve fixed the performance issue really quickly and gone from data to fix much faster than you could have ever done before.
Do you have anything to add on that, Phil? I’m sure you have so many thoughts on the future of performance work. We have seen a lot of anecdotal success. Okay. Operative term, everybody: anecdotal. I have no numbers, but we’ve seen a lot of anecdotal success around using simulators.
You know, you guys can sue me later. Using simulators for doing things like taking performance data from production, basically saying, oh, this is a signature of a hang issue, spinning up a simulator to try to reproduce that issue, using something like a UI test with measure blocks and all those things and Instruments in the background, and then basically telling an agent very directly, reproduce this issue that is happening in the field, and do not pass fix until you are able to reproduce it, and then write a fix and make sure that the reproduction no longer occurs before you put up a PR. We’ve seen a lot of success doing stuff like that, and I think the bottom line is, when you add these kinds of constraints around these workflows, I’m not going to call it a loop, because at some point, it terminates. But when you have… Yeah, hopefully.
I haven’t looked at the bill yet at the end of the month, but when you have loops like this or workflows like this that have really hard constraints around reproduction, especially with performance issues and crashes and anything that represents in this sort of quality vector, reproduction gates are really key, because it not only tells the agent, this is when you’re done, but it also makes sure that the agent stays on track for trying to solve that particular problem.
A lot of times, when we do this without the sort of, we’ll call them repro gates, when we do this without the sort of reproduction gates, a lot of the times, we see the agents, like, I found these three other bugs too, and then it goes off and tries to fix those, which is great, but that’s not the point of that exercise.
And what you might end up with is a large PR or a large set of PRs that then need to be reviewed and kind of negotiated in that scope. And so everything Shefali said is perfectly right. It’s just adding the hard requirement of, you need to reproduce this problem and use the available tools to detect and validate that reproduction before you move forward, is really key in getting a lot more success out of the workflow.
Gotcha. I see some other questions. A lot of these were actually submitted earlier this morning. We talked a bit about peer benchmarks and goals and kind of figuring out where do you shoot for. There’s kind of a more general question, which is, are there any industry benchmarks for hangs, scroll performance, crash rate, launch time? How do you know when good is good enough, kind of thing, I think, is the question. I know that’s almost an unfair question, but I’m going to throw it anyway.
Wow. How is good good enough? I think a big thing that defines that is whether or not you can hand your app to somebody who’s never used it before, and it looks and feels magical. I know that that sounds really cliche. It’s very Californian. But it is very true in the sense that, I think, I’ll give a sort of core example. My mom is a big Apple fan, uses Apple devices.
I have a text from her almost every single day about an app that she’s using that has some kind of problem. And she’s like, can you fix it? I’m like, Mom, I work for Apple, not that company. I’m glad it’s a universal experience. Yeah, it’s a pretty universal experience, I think, if you work at Apple.
And I think the sort of key there is that the fact that somebody like my mother, who is obviously great and smart and whatever, can see an issue like that and immediately connect it with, oh, that’s a problem that kind of disembarks me from the experience of using this app, is a pretty good metric of whether or not you’re good enough.
Right? I think some of the best apps that we use, we talked about a couple of great examples, like Notion and Tinder today. Some of the best apps that we have and we use every day, or some folks use, is they do feel magical in your hands. They do feel like a really good and smooth experience.
And I think that that’s kind of, in my mind, it’s not based on a data point or a line in a graph, like you talked about the peer group benchmarks and all that. But it is based on people’s experience using the product. And that’s kind of where I would say is, that’s when you kind of know it’s good enough.
Maybe you stop hearing as many people talking about how your app is crashing when they’re using it, or otherwise. I would also… - Oh, go ahead. - No, go ahead. I would also add that it’s always a good idea to ask yourself the question of what’s caused me to go to the app switcher and quit an app before.
And if your app does kind of the same thing, then that’s probably a really good area to try and optimize. Because I’m guilty of getting frustrated and then just quitting the app and being like, I’m going to come back to that later. And you just don’t want that experience from people that are using your app. So it’s a good question to ask.
I was going to say it’s also easy to get hyperfixated on the metrics rather than the actual human experience, because when you open Instruments and you see hitches, and you’re like, I’ve got to make all of those go away. But the question really should be, when somebody is scrolling through my content, are they noticing the hitches? Is there any perceivable disruption? Because otherwise, you can sort of drive yourself up the wall trying to get rid of all of these things. And it may not necessarily be the best way to be spending time for something that may not be noticeable.
Yeah, totally. Since you mentioned hitches, I have a question about hitches here that I’ll throw out there. The question is, Xcode Organizer shows you kind of a hitch metric across the whole app. So is there anything that would let you break that down further if you wanted to understand what part of your app is contributing to those hitches?
This feels like one part us and then one part… Yeah, maybe you both want to start. You’re the Xcode Organizer… Well, you can do this in MetricKit, right? Yeah, you can do that in MetricKit. The Organizer does aggregate across the entire app. So it’s going to be all animations for your app.
That’s a great question. Unfortunately, we don’t have anything today that can do that. But MetricKit… Great feedback report. - Yeah. - Feature request. I’ll be on the lookout, because all of those come to me. So if anyone here asks that question, please file that. But yeah, you can use MetricKit. And then that gives you the ability to then go a step further and trace your app and profile your app to see where, what exactly caused it and how do you go about fixing it.
I’d say the challenge also with using MetricKit for something like this is that we have these os_signpost-based APIs that are kind of old now. And we have animation begin and animation end, these interval signposts that fundamentally, I think a lot of us, when we try to reason about how our UI is working, we’re not thinking about intervals. We’re thinking about things loading sort of almost in parallel sometimes. And I think that one of the things that the MetricKit 27 APIs do really well is they let you kind of think more about what state is my app in from a product perspective.
So the StateReporting APIs and the integration with the StateReporting framework allow you to think more of, hey, this is the buy page, or this is the save action, or it lets you take these sort of more qualifiers-type product features, and then MetricKit does the intersection for you. So you can see things like, oh, let’s say on the view page, for example, the hitch rate was this during this particular time of this particular payload that covers this time range.
And then you can kind of intersect that with other things, like, oh, my app was in a state of sync for online content, or something like that, which helped kind of build a better understanding of the sort of animation hitches that are occurring, but in the context of other things that your app is doing.
And Steven, you’ve debugged a lot of SwiftUI hitches in your day. What tools do you go for, specifically in the context of SwiftUI, where if you were to just take a Time Profiler trace, you’re mostly just going to see SwiftUI code running? It’s not necessarily going to map back to your code.
Yeah. So the template for the SwiftUI instrument includes the Hitches instrument automatically. I generally like to just look for whatever area of the app has the most animation. Usually, scrolling is one of the main opportunities for getting better app performance. And so typically, what I like to do is look at the time in the timeline in Instruments when a hitch occurs, and also expand the Hitches instrument to actually see when the update happened, because a hitch tends to land a little bit later than when the actual work is happening.
So looking at the update interval and lining that up with the SwiftUI work in the SwiftUI instrument can give you a sense of what updates are either taking too long, because maybe there’s something synchronous that you’re accidentally doing in your view body, or frequent updates, like you’re churning things faster than you would expect to.
And then I generally just look to try to reduce that and first see, can the hitch get shorter? Can I get it down to the point where it may not be noticeable, even if I can’t get it to completely go away in a certain pressured situation? That’s another area where people get hyperfixated on the metrics, right? Because we talk about hitch rate, it’s like if it’s 1 millisecond per second, that’s imperceptible, right?
And one thing that I’ll call out too is I think that people have a tendency, because they want to iterate quickly, to go in and change their scheme, to switch to debug mode when profiling. And that’s not a good idea, because profiling in debug mode, you’re guaranteed to get worse results.
And so I know it can be useful for counting updates sometimes, sort of like we were talking about the simulator, right? That it’s good for getting directional information, but ultimately, to understand what people are experiencing, you really need to be on a device in release mode. And that counts for things like debugPrint as well. There are certain things that happen in compiler optimization where you might be printing something in your view body or doing a debug print.
And you might see, I’m seeing a body that looks like it’s updating five times, and you’re in debug mode. And what you don’t realize is that the compiler optimizes some of those updates out. And maybe you wouldn’t have even seen those updates. So just continually checking the release configuration to make sure you’re getting an accurate representation of what’s happening is important.
Totally. To your point, profiling as release is also going to give you symbols for your app in the call stack when you’re profiling. So if you really want to know what’s happening in your app, you definitely don’t want to be in debug mode. Totally. Yeah. And that’s when you use the Command-I shortcut earlier, Xcode does that for you when you choose that option. Yes.
So Adenine, I have a question for you. And I know this is a bit lower level in terms of APIs than we’ve talked about some others. So feel free to say, I want to check the documentation. But the question is, it’s kind of interesting, because I think we see this kind of category of problem a bit. This developer is using a third-party SDK, and they think that something in the SDK’s code is basically locking the display rate to 120 frames per second when it doesn’t need to be.
Is there any sort of, please override what other code is doing and lower the frame rate? Or do you kind of just have to own what that SDK is doing? Yeah, unfortunately, not to my knowledge. You do kind of have to own it. You can definitely make feedback requests to them, potentially. It’s not something that’s inherent to the SDK. It’s something that you might be triggering in your code with your usage of it that you can potentially do less of.
But yeah, unfortunately, if something is locking it to 120 frames per second, barring other things happening in the system, device doesn’t know any better. It doesn’t know your intents. So it’s going to run 120 frames per second. Definitely. And Phil and Shefali, excuse me, you folks have seen this category of problem before, right? Where it’s like, this third-party SDK is doing bad things, and it’s hurting my performance.
Maybe it’s hurting my launch time, because it’s running all these static initializers. And there’s not really a way to say, please don’t run the static initializers. I mean, maybe there is, but it would probably break things. Yeah. What’s the right way to think about this problem? How do you kind of make sure you have good performance, but sometimes you have code that’s coming from other sources?
Yeah. I mean, it’s a hard problem, not because inherently you can’t see these things, but because a lot of these problems, sometimes these SDK providers won’t even see it themselves, because a lot of these problems might happen on the first time the app is launched ever on a particular system or right after first update. Or maybe it’s just because the phone restarted or something. There’s these sorts of edge-case-type scenarios where testing for these things is difficult.
And I think ultimately, what I’ve seen teams have success with in this regard is, one, having a really rigorous process for testing some of these sort of core metrics on new version release. So for something like app launch, for example, everybody’s going to get their app launched at some point. There’s very, very few apps that just don’t launch ever. Yeah.
That explains a lot. But I think, generally speaking, it’s also the easiest thing to test, right? We have facilities within XCTest performance testing that do this. And setting up these types of tests when you introduce new frameworks, maybe large service SDKs or large sort of functional scales that do things that maybe are core to the app, is kind of creating these baselines and running these tests.
So for example, in the sort of launch delay category, right? Sometimes, we’ll see people link frameworks that inadvertently, like you said, run static initializers. And that’s absolutely something that you can test for, and you can see within your code. I mean, it’s very obvious. You see the static initializer running. It’s at the load methods, right?
And just being watchful of those things is kind of a strategy. Ultimately, it’s kind of, collect the data and work with whoever is providing you that framework to fix these problems. Yeah. And a lot of these framework owners should care. I mean, unless they’re defunct frameworks, but most of the time, they care.
In my experience, they care. And so working with them and providing them that feedback is really important. Just like we value feedback at Apple for our frameworks and fixing our bugs, which exist, these teams also do. These are products, just like all the things that we’re building, like apps and systems.
Going back to some of the AI stuff with UI frameworks, maybe, Luca, I’ll put this on you. I know you’re mostly focused on SwiftUI, but you also talked about some of the other skills that are available. Adaptability was up there. The question is specifically around UIKit. Are there any skills that touch UIKit APIs? But also just in general, do you want to talk a little bit about what some of the other skills are and what people can expect from those?
Yeah. So the adaptability is the one that definitely touch on UIKit as well. So again, the main purpose was to help your app layout be ready for iPhone Duo. There are suggestions on modern practices. Actually, the adaptability is a big collection of modern UIKit practices to follow. And if you follow modern UIKit practices, your app is ready for iPhone Duo. So that’s one example of a skill that touches on multiple UI framework.
Steven, do you have anything to add for some of the other skills that are available and your experience with them? I’ll be honest, there are so many of them that I haven’t… I have not looked at all of them, but I would like to go back and read them, since I’m telling all of you to go and read the skills. I honestly would recommend looking at all of them. I know there’s an App Intents one, which, App Intents are a really important part of the platform that I feel like it’s valuable for people to be looking at.
Yeah. I think there’s also an interesting one, if I remember correctly, on bounds checking in C. So if you have very low-level code that is working with C, that’s the one around security. So yeah, there’s definitely a broad spectrum of skill. Excellent. And also, please send us feedback about skills that you would like to see or things that you think are missing. We’re very interested to hear about how the skills are working for people.
Totally. Okay. There’s like three different questions here that I’m going to try and summarize. Shefali, I think this is for you. I think you mentioned this briefly in your talk, but maybe you can expand on it a little bit. There’s questions around, people have been talking about their experience having agents look at traces, and they’re saying, it dumped it to XML, and it ate a bajillion tokens trying to figure out what was wrong. And my understanding was that some of the things that you talked about is actually to help with token efficiency, but you want to talk about that a little more?
Yeah. I think something that we’ve noticed and observed is that a lot of what the agent will do is convert data into formats that it is comfortable operating on, and that obviously eats your tokens. And the most precious commodity right now, I think, is tokens, right? And so I mentioned this in the context of xctrace, but something great that it does is convert your data into a format that’s easy to parse.
And then the agent is able to take that data and easily understand what pieces it needs to read, what it doesn’t, what it needs in order to operate on your codebase, and is able to do that in the most token-efficient way. And I think that this is probably true for a lot of the tools that we have.
We’ve put an immense amount of care and consideration into making sure it is as efficient as possible, so that what you’re able to do with our tools is not using the majority of your budget, and then you can go and do more with the tokens that you do have to continue ideating and creating and making your app as cool as it can possibly be.
Yeah. Yeah. And that was kind of what I found interesting about your demo, is when you scrolled up in the transcript, the first thing the agent did was triage. Yes. And I’m assuming it’s doing that because triage is going to be a lot more efficient than using the show command and going over the entire timeline. - Right. - Absolutely.
Triage takes the trace and basically tells you, is there anything meaningful here for me to do with this information? And what do I do, and what time period should I care about? And then show can then take it, expand on it, and continue rolling. If it doesn’t find anything, it’ll just stop there. Gotcha.
Okay. One question that I have, and I’m going to be selfish and just ask my own question. I don’t see this here, but… You folks are solving performance problems every day, and there’s a whole bunch of different tools. And I think maybe Steven actually already has his answer.
You shared that you didn’t even know that you could tell the agent a clarifying question or suggestion inline in the coding assistant. But what is your secret tip or trick that you want to share? What’s the thing that you use, you’re not sure how well-known it is, and you just want to give it a little bit of spotlight? I mean, I hate to say the SwiftUI instrument.
I feel like people don’t necessarily always default to looking at Instruments. I think for a lot of people, their experience with Instruments may be the old SwiftUI instrument that existed before we shipped the new one. I think if it’s been a while since you’ve looked at Instruments, it’s definitely worth taking another look, because there have been some really cool advances across the board in the last couple of years. Awesome. How about anyone else? You got a favorite tool?
I can definitely say the debug rendering options in Xcode. Earlier, I demoed the Flash Updated Regions tool, which colors the places that are updating on the screen yellow. But there are several others that are all really, really powerful. Notably, I forget the exact verbiage, but one of them is called Compositor Fast Path. And between that and the color flush, if you have video as a main experience in your app, those two tools are really invaluable for making sure that video is as efficient as possible. Adenine, I’m not very familiar with what compositor fast path means.
Can you explain like I’m five? Yeah. So the system isn’t just drawing your app. It’s also, trivially, on normal phones, also drawing the time or the battery or whatever else. And then on Duo, it’s not just drawing your app. It’s drawing the other app, potentially, or whatever else is on the screen.
And so the compositor is a thing that takes everything and composites it into one final image to be displayed to the real screen. And there’s a fast path in this that’s for video and Metal rendering and a couple of other things, which skips a bunch of work when it meets certain conditions.
And so if the compositor fast path is, I believe it’s blue, then you’re getting that compositor fast path, and you’re taking significantly less energy and running significantly faster. And if it’s red, I believe, don’t quote me on those colors, then you’re missing that compositor fast path, and you should figure out why that is.
And if you can fix it, that will save a whole bunch of power and will speed it up a lot. Great. I’m looking at the clock, and I think we need to wrap up for today’s Q&A. I want to thank my panelists for joining us today. Let’s give them a round of applause.
Thanks so much for joining us today. Thank you. Thank you. All right. And thank you for joining us here in person and online for this Q&A on power and performance in your apps. After today, let’s keep the discussion going. You can ask questions on the Apple Developer Forums, and you can send your feedback to us using Feedback Assistant. Have a great rest of your day, everyone. Thank you so much.