Profiling an iOS app

Performance Mid-level Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

Tapping Save freezes the UI for two seconds. What is the first step?

Options
Hint 1 of 1

Measure where it really runs.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Profile a Release build on a device with Time Profiler and Hangs, and find the heaviest main-thread stack

Correct. It shows exactly what blocks the main thread.

Why not the others?
  • B Move all code in the save path to Task.detached. That's guessing, and it can introduce data races.
  • C Profile a Debug build in the simulator. The numbers won't match real devices.
  • D Add print timestamps everywhere. It's slow to set up and misses system work.

30-second answer

Reproduce the problem on a real device with a Release build, then use the right Instruments template: Time Profiler for CPU, Hangs and Animation Hitches for UI responsiveness, Allocations and Leaks for memory, App Launch for start-up, and Energy Log for battery. Add os_signpost intervals around your own work so traces show your app's phases. Fix the heaviest stack, then measure again.

Practise saying it · 45 s. No recording, just a timer

Describe how you profile.

Say your answer out loud, then check which of these points you covered:

  • Device + Release
  • Right instrument
  • Signposts
  • Measure again

Deep dive

Debug builds and the simulator have different performance from Release on device.

MetricKit and Xcode Organizer show field data from real users.

Use OSSignposter to mark intervals that appear in Instruments.

Set budgets (for example launch under 400 ms to first frame) and track them.

Common mistakes

  • Profiling Debug builds in the simulator.
  • Optimising without measuring.

Senior take & follow-ups

Seniors measure on device, fix the top cost and measure again.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why profile Release builds?

    Show hint

    Optimisations change what's slow.

  2. Where do you see real users' hangs?

    Show hint

    Xcode Organizer and MetricKit.

Suggest a fix if something here is wrong or out of date.