Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(dev): uncaught error on app start introduced by #11206 #11218

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions src/libs/Performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,27 @@ if (Metrics.canCapturePerformanceMetrics()) {
perfModule.setResourceLoggingEnabled(true);
rnPerformance = perfModule.default;

const measureFailSafe = (measureName, startOrMeasureOptions, endMark) => {
try {
rnPerformance.measure(measureName, startOrMeasureOptions, endMark);
} catch (error) {
// Sometimes there might be no start mark recorded and the measure will fail with an error
console.debug(error.message);
}
};

// Monitor some native marks that we want to put on the timeline
new perfModule.PerformanceObserver((list, observer) => {
list.getEntries()
.forEach((entry) => {
if (entry.name === 'nativeLaunchEnd') {
rnPerformance.measure('nativeLaunch', 'nativeLaunchStart', 'nativeLaunchEnd');
measureFailSafe('nativeLaunch', 'nativeLaunchStart', 'nativeLaunchEnd');
}
if (entry.name === 'downloadEnd') {
rnPerformance.measure('jsBundleDownload', 'downloadStart', 'downloadEnd');
measureFailSafe('jsBundleDownload', 'downloadStart', 'downloadEnd');
}
if (entry.name === 'runJsBundleEnd') {
rnPerformance.measure('runJsBundle', 'runJsBundleStart', 'runJsBundleEnd');
measureFailSafe('runJsBundle', 'runJsBundleStart', 'runJsBundleEnd');
}

// We don't need to keep the observer past this point
Expand All @@ -82,27 +91,22 @@ if (Metrics.canCapturePerformanceMetrics()) {
new perfModule.PerformanceObserver((list) => {
list.getEntriesByType('mark')
.forEach((mark) => {
try {
if (mark.name.endsWith('_end')) {
const end = mark.name;
const name = end.replace(/_end$/, '');
const start = `${name}_start`;
rnPerformance.measure(name, start, end);
}

// Capture any custom measures or metrics below
if (mark.name === `${CONST.TIMING.SIDEBAR_LOADED}_end`) {
// Make sure TTI is captured when the app is really usable
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
rnPerformance.measure('TTI', 'nativeLaunchStart', mark.name);
Performance.printPerformanceMetrics();
});
if (mark.name.endsWith('_end')) {
const end = mark.name;
const name = end.replace(/_end$/, '');
const start = `${name}_start`;
measureFailSafe(name, start, end);
}

// Capture any custom measures or metrics below
if (mark.name === `${CONST.TIMING.SIDEBAR_LOADED}_end`) {
// Make sure TTI is captured when the app is really usable
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
measureFailSafe('TTI', 'nativeLaunchStart', mark.name);
Performance.printPerformanceMetrics();
});
}
} catch (error) {
// Sometimes there might be no start mark recorded and the measure will fail with an error
console.debug(error.message);
});
}
});
}).observe({type: 'mark', buffered: true});
Expand All @@ -122,7 +126,9 @@ if (Metrics.canCapturePerformanceMetrics()) {
.map(entry => `\u2022 ${entry.name}: ${entry.duration.toFixed(1)}ms`)
.value();

Alert.alert('Performance', stats.join('\n'));
if (stats.length > 0) {
Alert.alert('Performance', stats.join('\n'));
}
};

/**
Expand Down