Datadog Yassir Ramdani and Austin Lai Apr 18, 2024

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

Critical Insight

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.

The team discovered that SwiftUI's diffing mechanism was causing double the expected View evaluations, and the fix required rethinking how their result builder worked.

About This Article

Problem

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.

Solution

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.

Impact

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.