Files
react-native/Libraries/WebPerformance/MemoryInfo.js
T
Xin Chen 70fb2dce45 Add performance.memory API
Summary:
This diff adds new performance API `memory`, which is a read-only property that gets the current JS heap size from native side.

Note that the JSI API returns an unordered map with unknown list of memory information, which is different from the [web spec](https://fburl.com/p0vpbt33). We may enforce specific memory info type on the JSI API so that it can be properly translate to the web spec.

- Update the JS spec
- Update Native implementation and return memory information with JSI API `jsi::instrumentation()::getHeapInfo()`
- Add native performance module to catalyst package

Changelog:
[General][Added] - Add performance memory API with native memory Info

Reviewed By: rubennorte

Differential Revision: D43137071

fbshipit-source-id: 319f1a6ba78fce61e665b00849ecf2579094af83
2023-02-15 20:52:48 -08:00

46 lines
1.1 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;
}
}
get jsHeapSizeLimit(): ?number {
return this._jsHeapSizeLimit;
}
get totalJSHeapSize(): ?number {
return this._totalJSHeapSize;
}
get usedJSHeapSize(): ?number {
return this._usedJSHeapSize;
}
}