Skip to content

Screen Load Time

Tracking Screen Load Time

In this example, we’ll track the time it takes to load the Details screen from the Home screen. This includes adding markers for navigation start and screen load completion.


Step 1: Initial Code

Here’s the base implementation of the two screens:

import { View, Button } from 'react-native';
// Home Screen
const HomeScreen = ({ navigation }) => {
8 collapsed lines
return (
<View>
<Button
title="Go to Details"
onPress={() => navigation.navigate('Details')}
/>
</View>
);
};
// Details Screen
const DetailsScreen = () => {
5 collapsed lines
return (
<View>
<Text>Details Screen</Text>
</View>
);
};

Step 2: Adding marco for Performance Tracking

Let’s modify the code to include PerformanceTracker.

  • Marker 1: Add a marker in the onPress handler of the “Go to Details” button to track when navigation starts.
  • Marker 2: Wrap the Details screen with PerformanceTracker to track when the screen finishes loading.
  • Persist Data: Use PerformanceTracker.configure({ persistToFile: true }) to save the performance data to a file on the device.
  • Handle onTrackingEnd: Capture the renderTime and drawTime values and optionally send them to a server.
HomeScreen.tsx
import { PerformanceTracker } from '@d11/marco';
PerformanceTracker.configure({
persistToFile: true
})
const HomeScreen = ({ navigation }) => {
return (
<View>
<Button
title="Go to Details"
onPress={() => {
// Track navigation start
PerformanceTracker.track('Navigation_Started', Date.now());
navigation.navigate('Details');
}}
/>
</View>
);
};
DetailsScreen.tsx
import { PerformanceTracker } from '@d11/marco';
const DetailsScreen = () => {
return (
<PerformanceTracker tagName="Details_Screen_Loaded" onTrackingEnd={(event) => {
// 'Draw Timestamp:', event.nativeEvent.drawTime
// 'Render Timestamp:', event.nativeEvent.renderTime
}}>
<View>
<Text>Details Screen</Text>
</View>
</PerformanceTracker>
);
};

Step 3: Automating the Test with Maestro

We’ll use Maestro to run a simple test to measure screen load time.

Create a test.yaml file with the following content:

test.yaml
appId: com.example.app # Replace with app's ID
---
- launchApp:
clearState: true
- repeat:
times: 2
commands:
- tapOn: "Go to Details"
- assertVisible: "Details Screen"

Step 4: Create a marco.config.js File

To configure the marco CLI, create a marco.config.js file at the root of project. This file specifies how marco will fetch the performance data from the device and visualize it on dashboard. You can either use CLI commands as well.

Here`s an sample configuration:

marco.config.js
module.exports = {
android: {
packageName: 'com.example.app',
outputPath: './navigation-reports/android',
dataDir: './navigation-reports/android/log.json',
port: '8080',
},
ios: {
packageName: 'com.example.app',
outputPath: './navigation-reports/ios',
dataDir: './navigation-reports/ios/log.json',
port: '8080',
},
};

Step 5: Fetch the Report

yarn marco generate --platform android

The command collects data saved in device to a JSON file at specified path(./navigation-reports/android/log.json) at the root of project.

Sample Report:

[
{
"tagName": "Navigation_Started",
"timestamp": 1733301898369
},
{
"tagName": "Details_Screen_Loaded",
"timestamp": 1733301898878
},
{
"tagName": "Navigation_Started",
"timestamp": 1733301904456
},
{
"tagName": "Details_Screen_Loaded",
"timestamp": 1733301905063
},
]

Step 6: Visualize the Data

To visualize the fetched performance data, you can use the marco visualization dashboard. This step helps you analyze the data in a more user-friendly and interactive way.

Run the Visualization Command

yarn marco visualize --platform android

This command starts a local server and opens the visualization dashboard in browser at http://localhost:8080 (or the custom port specified in marco.config.js).

Example Dashboard View

Once the dashboard is running, you’ll see the fetched data visualized in an intuitive format. For example:

  • Timeline View: Displays the sequence of tracked events.
  • Comparisons: If multiple test runs are available, you can compare trends across iterations.