@@ -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 }
0 commit comments