Building A Performant iOS Profiler
Article Summary
Indragie Karunaratne from Sentry reveals how they built a production-ready iOS profiler that runs on millions of real user devices. Most profilers only work locally, but this one collects real-world performance data without killing your app's performance.
Sentry's engineering team needed to profile iOS apps in production across different devices and conditions, not just during local development. They built a sampling profiler that could run in-process on user devices while maintaining minimal overhead, navigating iOS sandboxing limitations and async-signal-safety challenges along the way.
Key Takeaways
- Achieved under 5% average CPU overhead on mid-tier iOS devices
- Sampling at 100Hz captures functions running longer than 10ms
- Signal handlers failed: unreliable delivery and couldn't profile GCD worker threads
- Mach thread suspend APIs proved more reliable than POSIX signals
- Millions of profiles ingested from production devices over 5 months
Sentry built a sampling profiler that runs in production iOS apps with under 5% CPU overhead by using Mach thread suspend APIs and frame pointer stack walking.