diff --git a/Libraries/WebPerformance/MemoryInfo.js b/Libraries/WebPerformance/MemoryInfo.js
index fb469514e04..5a5abf0e6c8 100644
--- a/Libraries/WebPerformance/MemoryInfo.js
+++ b/Libraries/WebPerformance/MemoryInfo.js
@@ -31,14 +31,23 @@ export default class MemoryInfo {
}
}
+ /**
+ * The maximum size of the heap, in bytes, that is available to the context
+ */
get jsHeapSizeLimit(): ?number {
return this._jsHeapSizeLimit;
}
+ /**
+ * The total allocated heap size, in bytes
+ */
get totalJSHeapSize(): ?number {
return this._totalJSHeapSize;
}
+ /**
+ * The currently active segment of JS heap, in bytes.
+ */
get usedJSHeapSize(): ?number {
return this._usedJSHeapSize;
}
diff --git a/Libraries/WebPerformance/Performance.js b/Libraries/WebPerformance/Performance.js
index 0c071583cfb..384d5d3a895 100644
--- a/Libraries/WebPerformance/Performance.js
+++ b/Libraries/WebPerformance/Performance.js
@@ -110,14 +110,15 @@ export default class Performance {
const memoryInfo = NativePerformance.getSimpleMemoryInfo();
if (memoryInfo.hasOwnProperty('hermes_heapSize')) {
// We got memory information from Hermes
- const {hermes_heapSize, hermes_allocatedBytes} = memoryInfo;
- const totalJSHeapSize = Number(hermes_heapSize);
- const usedJSHeapSize = Number(hermes_allocatedBytes);
+ const {
+ hermes_heapSize: totalJSHeapSize,
+ hermes_allocatedBytes: usedJSHeapSize,
+ } = memoryInfo;
return new MemoryInfo({
jsHeapSizeLimit: null, // We don't know the heap size limit from Hermes.
- totalJSHeapSize: isNaN(totalJSHeapSize) ? null : totalJSHeapSize,
- usedJSHeapSize: isNaN(usedJSHeapSize) ? null : usedJSHeapSize,
+ totalJSHeapSize,
+ usedJSHeapSize,
});
} else {
// JSC and V8 has no native implementations for memory information in JSI::Instrumentation
diff --git a/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js b/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js
index c75e9b9c35d..288c3c2cc97 100644
--- a/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js
+++ b/packages/rn-tester/js/examples/Performance/PerformanceApiExample.js
@@ -10,6 +10,7 @@
*/
'use strict';
+import type MemoryInfo from '../../../../../Libraries/WebPerformance/MemoryInfo';
import type ReactNativeStartupTiming from '../../../../../Libraries/WebPerformance/ReactNativeStartupTiming';
import * as React from 'react';
@@ -22,11 +23,7 @@ const performance = new Performance();
function MemoryExample(): React.Node {
// Memory API testing
- const [memoryInfo, setMemoryInfo] = useState<{
- jsHeapSizeLimit?: ?number,
- totalJSHeapSize?: ?number,
- usedJSHeapSize?: ?number,
- }>({});
+ const [memoryInfo, setMemoryInfo] = useState(null);
const onGetMemoryInfo = useCallback(() => {
// performance.memory is not included in bom.js yet.
// Once we release the change in flow this can be removed.
@@ -40,25 +37,13 @@ function MemoryExample(): React.Node {
- {`jsHeapSizeLimit: ${
- memoryInfo.jsHeapSizeLimit == null
- ? 'N/A'
- : memoryInfo.jsHeapSizeLimit
- } bytes`}
+ {`jsHeapSizeLimit: ${String(memoryInfo?.jsHeapSizeLimit)} bytes`}
- {`totalJSHeapSize: ${
- memoryInfo.totalJSHeapSize == null
- ? 'N/A'
- : memoryInfo.totalJSHeapSize
- } bytes`}
+ {`totalJSHeapSize: ${String(memoryInfo?.totalJSHeapSize)} bytes`}
- {`usedJSHeapSize: ${
- memoryInfo.usedJSHeapSize == null
- ? 'N/A'
- : memoryInfo.usedJSHeapSize
- } bytes`}
+ {`usedJSHeapSize: ${String(memoryInfo?.usedJSHeapSize)} bytes`}