Skip to content

Commit a2e3f41

Browse files
huntiefacebook-github-bot
authored andcommitted
Add internal support for PerformanceResourceTiming (#50996)
Summary: Adds a representation of the [`PerformanceResourceTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming) event type to the Web Performance subsystem, ahead of integration with our network event reporting. Changelog: [Internal] Differential Revision: D73861431
1 parent d63c735 commit a2e3f41

File tree

8 files changed

+67
-4
lines changed

8 files changed

+67
-4
lines changed

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9696,7 +9696,12 @@ declare export default class Performance {
96969696

96979697
exports[`public API should not change unintentionally src/private/webapis/performance/PerformanceEntry.js 1`] = `
96989698
"export type DOMHighResTimeStamp = number;
9699-
export type PerformanceEntryType = \\"mark\\" | \\"measure\\" | \\"event\\" | \\"longtask\\";
9699+
export type PerformanceEntryType =
9700+
| \\"mark\\"
9701+
| \\"measure\\"
9702+
| \\"event\\"
9703+
| \\"longtask\\"
9704+
| \\"resource\\";
97009705
export type PerformanceEntryJSON = {
97019706
name: string,
97029707
entryType: PerformanceEntryType,

packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ NativePerformanceEntry toNativePerformanceEntry(const PerformanceEntry& entry) {
6565
nativeEntry.processingEnd = eventEntry.processingEnd;
6666
nativeEntry.interactionId = eventEntry.interactionId;
6767
}
68+
if (std::holds_alternative<PerformanceResourceTiming>(entry)) {
69+
auto resourceEntry = std::get<PerformanceResourceTiming>(entry);
70+
nativeEntry.fetchStart = resourceEntry.fetchStart;
71+
nativeEntry.requestStart = resourceEntry.requestStart;
72+
nativeEntry.connectStart = resourceEntry.connectStart;
73+
nativeEntry.connectEnd = resourceEntry.connectEnd;
74+
nativeEntry.responseStart = resourceEntry.responseStart;
75+
nativeEntry.responseEnd = resourceEntry.responseEnd;
76+
nativeEntry.responseStatus = resourceEntry.responseStatus;
77+
}
6878

6979
return nativeEntry;
7080
}

packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ struct NativePerformanceEntry {
6161
std::optional<DOMHighResTimeStamp> processingStart;
6262
std::optional<DOMHighResTimeStamp> processingEnd;
6363
std::optional<PerformanceEntryInteractionId> interactionId;
64+
65+
// For PerformanceResourceTiming only
66+
std::optional<DOMHighResTimeStamp> fetchStart;
67+
std::optional<DOMHighResTimeStamp> requestStart;
68+
std::optional<DOMHighResTimeStamp> connectStart;
69+
std::optional<DOMHighResTimeStamp> connectEnd;
70+
std::optional<DOMHighResTimeStamp> responseStart;
71+
std::optional<DOMHighResTimeStamp> responseEnd;
72+
std::optional<std::string> responseStatus;
6473
};
6574

6675
template <>

packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntry.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include <react/timing/primitives.h>
11+
#include <optional>
1112
#include <string>
1213
#include <variant>
1314

@@ -21,7 +22,8 @@ enum class PerformanceEntryType {
2122
MEASURE = 2,
2223
EVENT = 3,
2324
LONGTASK = 4,
24-
_NEXT = 5,
25+
RESOURCE = 5,
26+
_NEXT = 6,
2527
};
2628

2729
struct AbstractPerformanceEntry {
@@ -51,11 +53,26 @@ struct PerformanceLongTaskTiming : AbstractPerformanceEntry {
5153
PerformanceEntryType::LONGTASK;
5254
};
5355

56+
struct PerformanceResourceTiming : AbstractPerformanceEntry {
57+
static constexpr PerformanceEntryType entryType =
58+
PerformanceEntryType::RESOURCE;
59+
/** Aligns with `startTime`. */
60+
std::optional<DOMHighResTimeStamp> fetchStart;
61+
std::optional<DOMHighResTimeStamp> requestStart;
62+
std::optional<DOMHighResTimeStamp> connectStart;
63+
std::optional<DOMHighResTimeStamp> connectEnd;
64+
std::optional<DOMHighResTimeStamp> responseStart;
65+
/** Aligns with `duration`. */
66+
std::optional<DOMHighResTimeStamp> responseEnd;
67+
std::optional<std::string> responseStatus;
68+
};
69+
5470
using PerformanceEntry = std::variant<
5571
PerformanceMark,
5672
PerformanceMeasure,
5773
PerformanceEventTiming,
58-
PerformanceLongTaskTiming>;
74+
PerformanceLongTaskTiming,
75+
PerformanceResourceTiming>;
5976

6077
struct PerformanceEntrySorter {
6178
bool operator()(const PerformanceEntry& lhs, const PerformanceEntry& rhs) {

packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class PerformanceEntryReporter {
109109
PerformanceEntryCircularBuffer longTaskBuffer_{LONG_TASK_BUFFER_SIZE};
110110
PerformanceEntryKeyedBuffer markBuffer_;
111111
PerformanceEntryKeyedBuffer measureBuffer_;
112+
PerformanceEntryKeyedBuffer resourceBuffer_;
112113

113114
std::unordered_map<std::string, uint32_t> eventCounts_;
114115

@@ -127,6 +128,8 @@ class PerformanceEntryReporter {
127128
return measureBuffer_;
128129
case PerformanceEntryType::LONGTASK:
129130
return longTaskBuffer_;
131+
case PerformanceEntryType::RESOURCE:
132+
return resourceBuffer_;
130133
case PerformanceEntryType::_NEXT:
131134
throw std::logic_error("Cannot get buffer for _NEXT entry type");
132135
}
@@ -143,6 +146,8 @@ class PerformanceEntryReporter {
143146
return measureBuffer_;
144147
case PerformanceEntryType::LONGTASK:
145148
return longTaskBuffer_;
149+
case PerformanceEntryType::RESOURCE:
150+
return resourceBuffer_;
146151
case PerformanceEntryType::_NEXT:
147152
throw std::logic_error("Cannot get buffer for _NEXT entry type");
148153
}

packages/react-native/src/private/webapis/performance/PerformanceEntry.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
// flowlint unsafe-getters-setters:off
1212

1313
export type DOMHighResTimeStamp = number;
14-
export type PerformanceEntryType = 'mark' | 'measure' | 'event' | 'longtask';
14+
export type PerformanceEntryType =
15+
| 'mark'
16+
| 'measure'
17+
| 'event'
18+
| 'longtask'
19+
| 'resource';
1520

1621
export type PerformanceEntryJSON = {
1722
name: string,

packages/react-native/src/private/webapis/performance/internals/RawPerformanceEntry.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const RawPerformanceEntryTypeValues = {
2424
MEASURE: 2,
2525
EVENT: 3,
2626
LONGTASK: 4,
27+
RESOURCE: 5,
2728
};
2829

2930
export function rawToPerformanceEntry(
@@ -95,6 +96,8 @@ export function performanceEntryTypeToRaw(
9596
return RawPerformanceEntryTypeValues.EVENT;
9697
case 'longtask':
9798
return RawPerformanceEntryTypeValues.LONGTASK;
99+
case 'resource':
100+
return RawPerformanceEntryTypeValues.RESOURCE;
98101
default:
99102
// Verify exhaustive check with Flow
100103
(type: empty);

packages/react-native/src/private/webapis/performance/specs/NativePerformance.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ export type RawPerformanceEntry = {
2828
processingStart?: number,
2929
processingEnd?: number,
3030
interactionId?: number,
31+
32+
// For PerformanceResourceTiming only
33+
fetchStart?: number,
34+
requestStart?: number,
35+
connectStart?: number,
36+
connectEnd?: number,
37+
responseStart?: number,
38+
responseEnd?: number,
39+
responseStatus?: string,
3140
};
3241

3342
export type OpaqueNativeObserverHandle = mixed;

0 commit comments

Comments
 (0)