Skip to content

fix: Use same implementation for performance.now() on iOS and Android #32695

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "RCTJSIExecutorRuntimeInstaller.h"

#import <React/RCTLog.h>
#include <chrono>

namespace facebook {
namespace react {
Expand All @@ -21,8 +22,7 @@
bindNativeLogger(runtime, iosLoggingBinder);

PerformanceNow iosPerformanceNowBinder = []() {
// CACurrentMediaTime() returns the current absolute time, in seconds
return CACurrentMediaTime() * 1000;
return std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
};
bindNativePerformanceNow(runtime, iosPerformanceNowBinder);

Expand Down
9 changes: 1 addition & 8 deletions ReactAndroid/src/main/jni/react/jni/NativeTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ namespace facebook {
namespace react {

double reactAndroidNativePerformanceNowHook() {
auto time = std::chrono::steady_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(
time.time_since_epoch())
.count();

constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0;

return duration / NANOSECONDS_IN_MILLISECOND;
return std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
}

} // namespace react
Expand Down