iOS Performance Monitoring with Datadog
Article Summary
Yassir Ramdani and Austin Lai from Datadog built a custom SwiftUI graphing library that renders thousands of data points without lag. Here's how they debugged performance bottlenecks that most iOS developers never see.
Datadog's mobile team needed native data visualization for their iOS app, but existing libraries couldn't handle their complex dashboards with thousands of data points. They built DogGraphs from scratch using SwiftUI, then had to solve serious performance issues when rendering graphs with 7,345+ data points across 113 lines.
Key Takeaways
- Reduced View body evaluations from 339 to 113 by restructuring coordinate system
- Batching shapes by style cut thousands of renders to just distinct styles count
- SwiftUI uses memcmp for POD types, Equatable when available, reflection as fallback
- Expensive logic in View bodies causes micro-hangs even with 15µs average duration
Strategic architectural changes and batching techniques eliminated rendering hangs in graphs with thousands of data points, now powering multiple products across Datadog's mobile app.
About This Article
DogGraphs was rendering thousands of rectangles at once in stacked bar charts. This caused noticeable hangs when users interacted with the charts, even though each View body evaluation only took about 15 microseconds.
Datadog created a Batch GraphContent type that groups shapes by their fill and stroke styles. Instead of rendering thousands of individual SwiftUI Shapes, each group renders as a single Path.
The batching approach cut shape instantiation down from thousands to just however many distinct styles existed. Rendering hangs during gesture interactions with complex graphs went away entirely.