Skip to content

Commit 6db9442

Browse files
rubennortekikoso
authored andcommitted
Remove optionality for stable methods of the NativePerformance module (facebook#52668)
Summary: Pull Request resolved: facebook#52668 Changelog: [internal] These methods have been available for months so no need to consider backwards compatibility with older binaries. Reviewed By: huntie Differential Revision: D78412932 fbshipit-source-id: 0f1d541c36c98a4cc8c847d1ee7a08a9d0f4b849
1 parent 74f810a commit 6db9442

File tree

3 files changed

+62
-58
lines changed

3 files changed

+62
-58
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ function getCachedEventCounts(): Map<string, number> {
8686
return cachedEventCounts;
8787
}
8888

89-
if (!NativePerformance || !NativePerformance?.getEventCounts) {
89+
if (!NativePerformance) {
9090
warnNoNativePerformance();
9191
cachedEventCounts = new Map();
9292
return cachedEventCounts;
9393
}
9494

9595
const eventCounts = new Map<string, number>(
96-
NativePerformance.getEventCounts?.() ?? [],
96+
NativePerformance.getEventCounts() ?? [],
9797
);
9898
cachedEventCounts = eventCounts;
9999

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

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -98,53 +98,56 @@ export default class Performance {
9898

9999
// Get the current JS memory information.
100100
get memory(): MemoryInfo {
101-
if (NativePerformance?.getSimpleMemoryInfo) {
102-
// JSI API implementations may have different variants of names for the JS
103-
// heap information we need here. We will parse the result based on our
104-
// guess of the implementation for now.
105-
const memoryInfo = NativePerformance.getSimpleMemoryInfo();
106-
if (memoryInfo.hasOwnProperty('hermes_heapSize')) {
107-
// We got memory information from Hermes
108-
const {
109-
hermes_heapSize: totalJSHeapSize,
110-
hermes_allocatedBytes: usedJSHeapSize,
111-
} = memoryInfo;
112-
113-
return new MemoryInfo({
114-
jsHeapSizeLimit: null, // We don't know the heap size limit from Hermes.
115-
totalJSHeapSize,
116-
usedJSHeapSize,
117-
});
118-
} else {
119-
// JSC and V8 has no native implementations for memory information in JSI::Instrumentation
120-
return new MemoryInfo();
121-
}
101+
if (!NativePerformance) {
102+
warnNoNativePerformance();
103+
return new MemoryInfo();
122104
}
123105

124-
return new MemoryInfo();
106+
// JSI API implementations may have different variants of names for the JS
107+
// heap information we need here. We will parse the result based on our
108+
// guess of the implementation for now.
109+
const memoryInfo = NativePerformance.getSimpleMemoryInfo();
110+
if (memoryInfo.hasOwnProperty('hermes_heapSize')) {
111+
// We got memory information from Hermes
112+
const {
113+
hermes_heapSize: totalJSHeapSize,
114+
hermes_allocatedBytes: usedJSHeapSize,
115+
} = memoryInfo;
116+
117+
return new MemoryInfo({
118+
jsHeapSizeLimit: null, // We don't know the heap size limit from Hermes.
119+
totalJSHeapSize,
120+
usedJSHeapSize,
121+
});
122+
} else {
123+
// JSC and V8 has no native implementations for memory information in JSI::Instrumentation
124+
return new MemoryInfo();
125+
}
125126
}
126127

127128
// Startup metrics is not used in web, but only in React Native.
128129
get rnStartupTiming(): ReactNativeStartupTiming {
129-
if (NativePerformance?.getReactNativeStartupTiming) {
130-
const {
131-
startTime,
132-
endTime,
133-
initializeRuntimeStart,
134-
initializeRuntimeEnd,
135-
executeJavaScriptBundleEntryPointStart,
136-
executeJavaScriptBundleEntryPointEnd,
137-
} = NativePerformance.getReactNativeStartupTiming();
138-
return new ReactNativeStartupTiming({
139-
startTime,
140-
endTime,
141-
initializeRuntimeStart,
142-
initializeRuntimeEnd,
143-
executeJavaScriptBundleEntryPointStart,
144-
executeJavaScriptBundleEntryPointEnd,
145-
});
130+
if (!NativePerformance) {
131+
warnNoNativePerformance();
132+
return new ReactNativeStartupTiming();
146133
}
147-
return new ReactNativeStartupTiming();
134+
135+
const {
136+
startTime,
137+
endTime,
138+
initializeRuntimeStart,
139+
initializeRuntimeEnd,
140+
executeJavaScriptBundleEntryPointStart,
141+
executeJavaScriptBundleEntryPointEnd,
142+
} = NativePerformance.getReactNativeStartupTiming();
143+
return new ReactNativeStartupTiming({
144+
startTime,
145+
endTime,
146+
initializeRuntimeStart,
147+
initializeRuntimeEnd,
148+
executeJavaScriptBundleEntryPointStart,
149+
executeJavaScriptBundleEntryPointEnd,
150+
});
148151
}
149152

150153
mark(
@@ -434,10 +437,11 @@ export default class Performance {
434437
* https://www.w3.org/TR/performance-timeline/#extensions-to-the-performance-interface
435438
*/
436439
getEntries(): PerformanceEntryList {
437-
if (!NativePerformance?.getEntries) {
440+
if (!NativePerformance) {
438441
warnNoNativePerformance();
439442
return [];
440443
}
444+
441445
return NativePerformance.getEntries().map(rawToPerformanceEntry);
442446
}
443447

@@ -450,7 +454,7 @@ export default class Performance {
450454
return [];
451455
}
452456

453-
if (!NativePerformance?.getEntriesByType) {
457+
if (!NativePerformance) {
454458
warnNoNativePerformance();
455459
return [];
456460
}
@@ -472,7 +476,7 @@ export default class Performance {
472476
return [];
473477
}
474478

475-
if (!NativePerformance?.getEntriesByName) {
479+
if (!NativePerformance) {
476480
warnNoNativePerformance();
477481
return [];
478482
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type PerformanceObserverInit = {
5353
};
5454

5555
export interface Spec extends TurboModule {
56-
+now?: () => number;
56+
+now: () => number;
5757
+reportMark?: (name: string, startTime: number, entry: mixed) => void;
5858
+reportMeasure?: (
5959
name: string,
@@ -62,36 +62,36 @@ export interface Spec extends TurboModule {
6262
entry: mixed,
6363
) => void;
6464
+getMarkTime?: (name: string) => ?number;
65-
+clearMarks?: (entryName?: string) => void;
66-
+clearMeasures?: (entryName?: string) => void;
67-
+getEntries?: () => $ReadOnlyArray<RawPerformanceEntry>;
68-
+getEntriesByName?: (
65+
+clearMarks: (entryName?: string) => void;
66+
+clearMeasures: (entryName?: string) => void;
67+
+getEntries: () => $ReadOnlyArray<RawPerformanceEntry>;
68+
+getEntriesByName: (
6969
entryName: string,
7070
entryType?: ?RawPerformanceEntryType,
7171
) => $ReadOnlyArray<RawPerformanceEntry>;
72-
+getEntriesByType?: (
72+
+getEntriesByType: (
7373
entryType: RawPerformanceEntryType,
7474
) => $ReadOnlyArray<RawPerformanceEntry>;
75-
+getEventCounts?: () => $ReadOnlyArray<[string, number]>;
75+
+getEventCounts: () => $ReadOnlyArray<[string, number]>;
7676
+getSimpleMemoryInfo: () => NativeMemoryInfo;
7777
+getReactNativeStartupTiming: () => ReactNativeStartupTiming;
7878

79-
+createObserver?: (
79+
+createObserver: (
8080
callback: NativeBatchedObserverCallback,
8181
) => OpaqueNativeObserverHandle;
82-
+getDroppedEntriesCount?: (observer: OpaqueNativeObserverHandle) => number;
82+
+getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle) => number;
8383

84-
+observe?: (
84+
+observe: (
8585
observer: OpaqueNativeObserverHandle,
8686
options: PerformanceObserverInit,
8787
) => void;
88-
+disconnect?: (observer: OpaqueNativeObserverHandle) => void;
89-
+takeRecords?: (
88+
+disconnect: (observer: OpaqueNativeObserverHandle) => void;
89+
+takeRecords: (
9090
observer: OpaqueNativeObserverHandle,
9191
sort: boolean,
9292
) => $ReadOnlyArray<RawPerformanceEntry>;
9393

94-
+getSupportedPerformanceEntryTypes?: () => $ReadOnlyArray<RawPerformanceEntryType>;
94+
+getSupportedPerformanceEntryTypes: () => $ReadOnlyArray<RawPerformanceEntryType>;
9595

9696
+setCurrentTimeStampForTesting?: (timeStamp: number) => void;
9797
+clearEventCountsForTesting?: () => void;

0 commit comments

Comments
 (0)