Files
react-native/Libraries/WebPerformance/MemoryInfo.js
T
Xin Chen f4e56fdf19 Refactor performance memory API implementation
Summary:
This diff refactors performance memory API and the RN Tester example.

- The returned value from C++ is number, so no need to cast
- Reuse `MemoryInfo` in RNTester example

Changelog:
[General][Internal] - Code refactor for performance memory API implementation

Reviewed By: rubennorte

Differential Revision: D43523878

fbshipit-source-id: 37d1f6a829a8eac45f7e3791ad36be0c199c6041
2023-03-07 18:32:20 -08:00

55 lines
1.3 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
// flowlint unsafe-getters-setters:off
export type MemoryInfoLike = {
jsHeapSizeLimit: ?number,
totalJSHeapSize: ?number,
usedJSHeapSize: ?number,
};
// Read-only object with JS memory information. This is returned by the performance.memory API.
export default class MemoryInfo {
_jsHeapSizeLimit: ?number;
_totalJSHeapSize: ?number;
_usedJSHeapSize: ?number;
constructor(memoryInfo: ?MemoryInfoLike) {
if (memoryInfo != null) {
this._jsHeapSizeLimit = memoryInfo.jsHeapSizeLimit;
this._totalJSHeapSize = memoryInfo.totalJSHeapSize;
this._usedJSHeapSize = memoryInfo.usedJSHeapSize;
}
}
/**
* 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;
}
}