A deep dive into hooking pure Swift functions at runtime using software breakpoints and protocol conformance descriptors. The technique enables automatic performance monitoring of SwiftUI view body accessors in debug builds by parsing protocol witness tables to find function addresses, then using mach exception handlers to intercept function entry and exit. While traditional Objective-C swizzling doesn't work for Swift, this approach leverages the Swift runtime's protocol conformance records and in-process debugging to achieve similar functionality. The ViewPerformance open-source package implements this for tracking SwiftUI view performance during development.

7m read timeFrom sentry.engineering
Post cover image
Table of contents
BackgroundFinding ViewsInstalling a hookIn productionConclusionFootnotes

Sort: