From 44109dc2c01a76baf37b836a378e6a28d96ea66c Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Tue, 28 Nov 2023 19:27:51 -0800 Subject: [PATCH] Fix warm start logging for ReactMarker (#41693) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41693 This diff fixes app warm start time. Before this change, we cache the first time when app start timing is logged, and ignore future loggings. Some apps are warm started and the startup time should be updated. Reviewed By: dmitry-voronkevich Differential Revision: D50481710 fbshipit-source-id: 03e00b75ee7ac578209ae3478adabe567e92a950 --- .../ReactCommon/cxxreact/ReactMarker.cpp | 17 +++++++++++++++-- .../ReactCommon/cxxreact/ReactMarker.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp b/packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp index e9059dac7137c8..86c3a03c9df5bf 100644 --- a/packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp +++ b/packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp @@ -53,9 +53,13 @@ void StartupLogger::logStartupEvent( double markerTime) { switch (markerId) { case ReactMarkerId::APP_STARTUP_START: - if (std::isnan(appStartupStartTime)) { - appStartupStartTime = markerTime; + if (!std::isnan(appStartupStartTime)) { + // We had a startup start time, which indicates a warm start (user + // closed the app and start again). In this case we need to invalidate + // all other startup timings. + reset(); } + appStartupStartTime = markerTime; return; case ReactMarkerId::APP_STARTUP_STOP: @@ -93,6 +97,15 @@ void StartupLogger::logStartupEvent( } } +void StartupLogger::reset() { + appStartupStartTime = std::nan(""); + appStartupEndTime = std::nan(""); + initReactRuntimeStartTime = std::nan(""); + initReactRuntimeEndTime = std::nan(""); + runJSBundleStartTime = std::nan(""); + runJSBundleEndTime = std::nan(""); +} + double StartupLogger::getAppStartupStartTime() { return appStartupStartTime; } diff --git a/packages/react-native/ReactCommon/cxxreact/ReactMarker.h b/packages/react-native/ReactCommon/cxxreact/ReactMarker.h index 8d3a532e2c4e0d..e50746780d4867 100644 --- a/packages/react-native/ReactCommon/cxxreact/ReactMarker.h +++ b/packages/react-native/ReactCommon/cxxreact/ReactMarker.h @@ -74,6 +74,7 @@ class RN_EXPORT StartupLogger { static StartupLogger& getInstance(); void logStartupEvent(const ReactMarkerId markerName, double markerTime); + void reset(); double getAppStartupStartTime(); double getInitReactRuntimeStartTime(); double getInitReactRuntimeEndTime();