Introducing Swift Profile Recorder: Identifying Performance Bottlenecks in Production
Article Summary
Apple just open-sourced the profiling tool they've used for years to debug Swift services at massive scale. No special privileges, no eBPF, no system dependencies required.
Swift Profile Recorder is an in-process sampling profiler that runs as a Swift Package, enabling performance profiling in sandboxed and restricted environments where traditional tools like eBPF or DTrace can't operate. Apple has battle-tested it across their latency-sensitive build infrastructure that powers OS development.
Key Takeaways
- Add profiling with just a package dependency, works in sandboxed environments
- Collect samples via curl over HTTP, no need to learn perf or eBPF
- Outputs to industry formats: perf script, pprof, FlameGraph collapsed format
- Apple uses it for both isolated performance regressions and continuous profiling
- Works on macOS and Linux without extra privileges or system components
Swift services can now profile production performance bottlenecks in restricted environments where traditional profiling tools can't run, using only a Swift Package and curl.
About This Article
Apple's distributed systems infrastructure on macOS and in sandboxed environments couldn't use traditional profiling tools like eBPF and DTrace. This made it hard to find performance bottlenecks in their latency-sensitive build and test infrastructure.
Johannes Weiss and Mitchell Allison's team built Swift Profile Recorder, an in-process sampling profiler distributed as a Swift Package. It collects samples through HTTP endpoints without needing kernel-level privileges or external system components.
Swift Profile Recorder works across different compute environments like Kubernetes and lambda functions. It outputs to industry-standard formats including Linux perf script, pprof, and FlameGraph collapsed format, which can be visualized in Speedscope and Firefox Profiler.