From 9e918dd5f775a40057500240516404fc7544fbad Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 5 Dec 2023 23:28:09 +0000 Subject: [PATCH] Move init time logging to a fn, add guard --- src/Navigation.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 4718349b58..31a8cd8d9e 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -471,12 +471,7 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { theme={theme} onReady={() => { SplashScreen.hideAsync() - const initMs = Math.round( - // @ts-ignore Emitted by Metro in the bundle prelude - performance.now() - global.__BUNDLE_START_TIME__, - ) - console.log(`Time to first paint: ${initMs} ms`) - logModuleInitTrace() + logModuleInitTime() }}> {children} @@ -585,7 +580,17 @@ const styles = StyleSheet.create({ }, }) -function logModuleInitTrace() { +let didInit = false +function logModuleInitTime() { + if (didInit) { + return + } + didInit = true + const initMs = Math.round( + // @ts-ignore Emitted by Metro in the bundle prelude + performance.now() - global.__BUNDLE_START_TIME__, + ) + console.log(`Time to first paint: ${initMs} ms`) if (__DEV__) { // This log is noisy, so keep false committed const shouldLog = false