Draw Time Tracking
Marco tracks when UI components are drawn on screen by hooking into platform-specific lifecycle methods. This allows measuring the time between component creation in JavaScript and when it becomes visible to users, helping identify performance bottlenecks.
High-Level Architecture
The following diagram shows the core components involved in draw time tracking:
Flow Description:
- JavaScript Component - Wrapped with PerformanceTracker
- Native View Creation - Platform-specific rendering begins
- Draw Time Detection - Calculate render time
- Event Dispatch - onTrackingEnd callback triggered
- Performance Store - Store metrics
Implementation Details
Marco uses different approaches for Android and iOS to detect when components are drawn on screen:
- Android: Uses the
onDraw()method of thePerformanceTrackerViewclass - iOS: Uses the
didMoveToWindow()method when a view is added to the window hierarchy
Both implementations ensure minimal overhead by only tracking the first draw of components.
Detailed Component Interaction
The following shows the complete flow of draw time tracking, from JavaScript initialization to final event handling:
Both platforms follow a similar approach but use platform-specific lifecycle methods to detect when a component is drawn on screen.
Key Points
- JavaScript Initialization: The PerformanceTracker component captures the initial timestamp when the component is created
- Native Bridge: Communication passes through React Native's bridge to native code
- Platform Detection: Each platform uses its native lifecycle methods to detect when drawing occurs
- Metrics Storage: Performance data is stored for later retrieval and analysis
- Event Callback: Optional callback allows real-time handling of performance metrics in JavaScript