Skip to content

Commit 0f276f1

Browse files
hoxyqfacebook-github-bot
authored andcommitted
Replace DOMHighResTimeStamp alias in ReactCommon with new abstractions (#50585)
Summary: Pull Request resolved: #50585 # Changelog: [Internal] Replaces `DOMHighResTimeStamp` alias completely in `ReactCommon` with `HighResTimeStamp`. `DOMHighResTimeStamp` as a type is now expected to be used only in JavaScript. I didn't update places where we explcitly use `std::chrono::high_resolution_clock`, since it is platform-specific and there is no guarantee that `std::chrono::high_resolution_clock` == `std::chrono::steady_clock`. Also, places that are isolated and not part of the Web Performance APIs, such as Telemetry for Fabric, are not updates as part of this diff. Although these subsystems are also using `std::chrono::steady_clock` as a low-level representation, they are not sharing it with other parts of the React Native core. Reviewed By: rubennorte Differential Revision: D72649815
1 parent d922635 commit 0f276f1

38 files changed

+625
-334
lines changed

packages/react-native/ReactCommon/cxxreact/JSExecutor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
#include "RAMBundleRegistry.h"
1111

1212
#include <jsinspector-modern/ReactCdp.h>
13-
#include <react/timing/primitives.h>
1413

1514
#include <array>
16-
#include <chrono>
1715

1816
namespace facebook::react {
1917

@@ -29,8 +27,8 @@ std::string JSExecutor::getSyntheticBundlePath(
2927
return buffer.data();
3028
}
3129

32-
double JSExecutor::performanceNow() {
33-
return chronoToDOMHighResTimeStamp(std::chrono::steady_clock::now());
30+
HighResTimeStamp JSExecutor::performanceNow() {
31+
return HighResTimeStamp::now();
3432
}
3533

3634
jsinspector_modern::RuntimeTargetDelegate&

packages/react-native/ReactCommon/cxxreact/JSExecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <folly/dynamic.h>
1515
#include <jsinspector-modern/InspectorInterfaces.h>
1616
#include <jsinspector-modern/ReactCdp.h>
17+
#include <react/timing/primitives.h>
1718

1819
#ifndef RN_EXPORT
1920
#define RN_EXPORT __attribute__((visibility("default")))
@@ -138,7 +139,7 @@ class RN_EXPORT JSExecutor {
138139
uint32_t bundleId,
139140
const std::string& bundlePath);
140141

141-
static double performanceNow();
142+
static HighResTimeStamp performanceNow();
142143

143144
/**
144145
* Get a reference to the \c RuntimeTargetDelegate owned (or implemented) by

packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,9 @@ void bindNativePerformanceNow(Runtime& runtime) {
556556
[](jsi::Runtime& runtime,
557557
const jsi::Value&,
558558
const jsi::Value* args,
559-
size_t count) { return Value(JSExecutor::performanceNow()); }));
559+
size_t /*count*/) {
560+
return JSExecutor::performanceNow().toDOMHighResTimeStamp();
561+
}));
560562
}
561563

562564
} // namespace facebook::react

packages/react-native/ReactCommon/jsinspector-modern/network/NetworkReporter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void NetworkReporter::reportRequestStart(
7878
int encodedDataLength,
7979
const std::optional<ResponseInfo>& redirectResponse) {
8080
if (ReactNativeFeatureFlags::enableResourceTimingAPI()) {
81-
double now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
81+
auto now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
8282

8383
// All builds: Annotate PerformanceResourceTiming metadata
8484
{
@@ -127,7 +127,7 @@ void NetworkReporter::reportRequestStart(
127127

128128
void NetworkReporter::reportConnectionTiming(const std::string& requestId) {
129129
if (ReactNativeFeatureFlags::enableResourceTimingAPI()) {
130-
double now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
130+
auto now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
131131

132132
// All builds: Annotate PerformanceResourceTiming metadata
133133
{
@@ -168,7 +168,7 @@ void NetworkReporter::reportResponseStart(
168168
const ResponseInfo& responseInfo,
169169
int encodedDataLength) {
170170
if (ReactNativeFeatureFlags::enableResourceTimingAPI()) {
171-
double now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
171+
auto now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
172172

173173
// All builds: Annotate PerformanceResourceTiming metadata
174174
{
@@ -205,7 +205,7 @@ void NetworkReporter::reportResponseStart(
205205

206206
void NetworkReporter::reportDataReceived(const std::string& requestId) {
207207
if (ReactNativeFeatureFlags::enableResourceTimingAPI()) {
208-
double now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
208+
auto now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
209209

210210
// All builds: Annotate PerformanceResourceTiming metadata
211211
{
@@ -233,7 +233,7 @@ void NetworkReporter::reportResponseEnd(
233233
const std::string& requestId,
234234
int encodedDataLength) {
235235
if (ReactNativeFeatureFlags::enableResourceTimingAPI()) {
236-
double now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
236+
auto now = PerformanceEntryReporter::getInstance()->getCurrentTimeStamp();
237237

238238
// All builds: Report PerformanceResourceTiming event
239239
{

packages/react-native/ReactCommon/jsinspector-modern/network/NetworkReporter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ using FrontendChannel = std::function<void(std::string_view messageJson)>;
3535
*/
3636
struct ResourceTimingData {
3737
std::string url;
38-
DOMHighResTimeStamp fetchStart;
39-
DOMHighResTimeStamp requestStart;
40-
std::optional<DOMHighResTimeStamp> connectStart;
41-
std::optional<DOMHighResTimeStamp> connectEnd;
42-
std::optional<DOMHighResTimeStamp> responseStart;
38+
HighResTimeStamp fetchStart;
39+
HighResTimeStamp requestStart;
40+
std::optional<HighResTimeStamp> connectStart;
41+
std::optional<HighResTimeStamp> connectEnd;
42+
std::optional<HighResTimeStamp> responseStart;
4343
std::optional<int> responseStatus;
4444
};
4545

packages/react-native/ReactCommon/jsinspector-modern/tracing/EventLoopReporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "EventLoopReporter.h"
99

1010
#if defined(REACT_NATIVE_DEBUGGER_ENABLED)
11+
#include <react/timing/primitives.h>
1112
#include "PerformanceTracer.h"
1213
#endif
1314

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Timing.h"
1010

1111
#include <oscompat/OSCompat.h>
12+
#include <react/timing/primitives.h>
1213

1314
#include <folly/json.h>
1415

packages/react-native/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <react/timing/primitives.h>
1515

16+
#include <react/timing/primitives.h>
17+
1618
#include <folly/dynamic.h>
1719
#include <functional>
1820
#include <mutex>

packages/react-native/ReactCommon/react/bridging/tests/BridgingTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ TEST_F(BridgingTest, highResTimeStampTest) {
784784
bridging::fromJs<HighResTimeStamp>(
785785
rt, bridging::toJs(rt, timestamp), invoker));
786786

787-
HighResDuration duration = HighResDuration::fromNanoseconds(1);
787+
auto duration = HighResDuration::fromNanoseconds(1);
788788
EXPECT_EQ(
789789
duration,
790790
bridging::fromJs<HighResDuration>(

packages/react-native/ReactCommon/react/nativemodule/intersectionobserver/NativeIntersectionObserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using NativeIntersectionObserverEntry =
5151
// isIntersectingAboveThresholds
5252
bool,
5353
// time
54-
double>;
54+
HighResTimeStamp>;
5555

5656
template <>
5757
struct Bridging<NativeIntersectionObserverEntry>

0 commit comments

Comments
 (0)