Skip to content

Commit

Permalink
Fix warm start logging for ReactMarker (#41693)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
Xin Chen authored and facebook-github-bot committed Nov 29, 2023
1 parent 88a55ba commit 44109dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/ReactCommon/cxxreact/ReactMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 44109dc

Please sign in to comment.