@onekeyfe/react-native-perf-memory 6.7.0-alpha.475 → 6.8.0-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +85 -28
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,9 +1,35 @@
1
+ <div align="center">
2
+
1
3
  # @onekeyfe/react-native-perf-memory
2
4
 
3
- Native process memory sampling for OneKey React Native applications on iOS and
4
- Android. The Nitro module returns one numeric byte count under the historical
5
- `rss` field. Callers own sampling frequency, aggregation and presentation;
6
- the package does not start a recurring sampler or upload measurements.
5
+ **Sample the app process's current memory footprint on iOS and Android.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-perf-memory?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-perf-memory)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-perf-memory?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Android](https://img.shields.io/badge/Android-3DDC84?logo=android&logoColor=white)
11
+ ![Nitro Modules](https://img.shields.io/badge/Nitro_Modules-4D6BFE)
12
+
13
+ </div>
14
+
15
+ A small Nitro HybridObject whose only method, `getMemoryUsage()`, returns the
16
+ current native process memory as `{ rss }` in bytes. iOS reads Mach
17
+ `phys_footprint` with a resident-size fallback; Android reads `VmRSS` from
18
+ `/proc/self/status` with a total-PSS fallback. The number covers the whole
19
+ process, not just the JavaScript heap, and the package never samples on a timer:
20
+ the caller owns frequency, aggregation and presentation.
21
+
22
+ ## Features
23
+
24
+ - **On-demand native sample** — one promise per measurement, with no background
25
+ timers, no uploads and no retained history.
26
+ - **Closest available metric per platform** — `phys_footprint` on iOS, `VmRSS`
27
+ on Android, each with a defined fallback.
28
+ - **Byte units** — one `number` in bytes under the historical `rss` field;
29
+ convert at the display layer.
30
+ - **Process-wide** — the result reflects the whole app process regardless of
31
+ which JS runtime asks.
32
+ - **Minimal surface** — a single method and a single exported type to wrap.
7
33
 
8
34
  ## Installation
9
35
 
@@ -11,8 +37,15 @@ the package does not start a recurring sampler or upload measurements.
11
37
  yarn add @onekeyfe/react-native-perf-memory react-native-nitro-modules
12
38
  ```
13
39
 
14
- Install the application's iOS pods and rebuild the native application. The
15
- measurement is performed by native code and requires the Nitro runtime.
40
+ Install the native peer packages this package links as well:
41
+
42
+ ```sh
43
+ yarn add @onekeyfe/react-native-native-logger
44
+ ```
45
+
46
+ The measurement is native, so install the application's iOS pods and rebuild the
47
+ native binary; a JavaScript-only update does not register the module. No platform
48
+ permission is required.
16
49
 
17
50
  ## Usage
18
51
 
@@ -21,39 +54,63 @@ import { ReactNativePerfMemory } from '@onekeyfe/react-native-perf-memory';
21
54
 
22
55
  const { rss } = await ReactNativePerfMemory.getMemoryUsage();
23
56
  const memoryMiB = rss / (1024 * 1024);
57
+
58
+ // Record time in the caller if a time series is needed.
59
+ const sample = { at: Date.now(), memoryMiB };
24
60
  ```
25
61
 
26
- ## Measurement semantics
62
+ Sample from a bounded diagnostic interval rather than on every render, and label
63
+ the platform and measurement kind alongside stored values.
64
+
65
+ ## API
66
+
67
+ | Export | Signature | Platforms | Description |
68
+ | --- | --- | --- | --- |
69
+ | `ReactNativePerfMemory.getMemoryUsage()` | `() => Promise<MemoryUsage>` | iOS, Android | Reads the current process memory in bytes. |
70
+ | `MemoryUsage` | `{ rss: number }` | iOS, Android | Result type; the value is bytes, not MiB. |
27
71
 
28
- `getMemoryUsage()` returns `Promise<{ rss: number }>` with the value in bytes.
29
- Despite the shared field name, the preferred measurements differ:
72
+ The measurement source differs by platform:
30
73
 
31
74
  | Platform | Preferred sample | Fallback |
32
75
  | --- | --- | --- |
33
- | iOS | Mach `phys_footprint` | Mach resident size, then zero. |
34
- | Android | `/proc/self/status` VmRSS | ActivityManager total PSS converted from KiB, then zero. |
76
+ | iOS | Mach `phys_footprint` | Mach resident size, then `0`. |
77
+ | Android | `/proc/self/status` `VmRSS` | `ActivityManager` total PSS (KiB converted to bytes), then `0`. |
78
+
79
+ There is no JavaScript-heap breakdown, allocation count or sampling timestamp.
80
+ See [`src/ReactNativePerfMemory.nitro.ts`](src/ReactNativePerfMemory.nitro.ts)
81
+ for the interface.
82
+
83
+ ## Platform support
84
+
85
+ | Capability | iOS | Android | Web |
86
+ | --- | :-: | :-: | :-: |
87
+ | On-demand process memory sample | ✅ | ✅ | — |
88
+ | `phys_footprint` source | ✅ | — | — |
89
+ | `VmRSS` / PSS source | — | ✅ | — |
90
+ | Background sampling or reporting | — | — | — |
91
+
92
+ ## Caveats
35
93
 
36
- A zero result can indicate that a measurement could not be obtained. It is not
37
- proof that the application has no memory usage. The number covers native process
38
- memory rather than only the JavaScript heap, and should not be compared across
39
- platforms as if both use an identical accounting method.
94
+ > [!WARNING]
95
+ > A `0` result means the measurement could not be obtained, not that the app uses
96
+ > no memory. Treat it as an unavailable sample and exclude it from averages.
40
97
 
41
- Use bounded sampling intervals suited to diagnostics rather than requesting a
42
- sample on every render. The exported interface is defined in
43
- [src/ReactNativePerfMemory.nitro.ts](src/ReactNativePerfMemory.nitro.ts).
98
+ > [!IMPORTANT]
99
+ > iOS and Android report different metrics (`phys_footprint` versus `VmRSS`).
100
+ > Do not compare their values as if they used identical accounting; record the
101
+ > platform and source with every sample.
44
102
 
45
- ## Reading a diagnostic sample
103
+ > [!NOTE]
104
+ > The sample is process-wide and has no timestamp. Keep sampling cadence,
105
+ > aggregation and any time-series key in the caller, and avoid reading it on
106
+ > every render.
46
107
 
47
- The named `ReactNativePerfMemory` object exposes only `getMemoryUsage()`.
48
- `MemoryUsage` is exported as a TypeScript type; it contains `rss`, with no
49
- JavaScript-heap breakdown, per-runtime allocation count or sampling timestamp.
50
- Record a timestamp in the caller if a time series needs one.
108
+ ## References
51
109
 
52
- A sample is process-wide even when requested from one JavaScript runtime.
53
- Keep platform, preferred/fallback measurement semantics and units alongside
54
- results when comparing runs. The module's zero fallback should be treated as
55
- an unavailable sample rather than included as measured zero consumption.
110
+ - [Native interface](src/ReactNativePerfMemory.nitro.ts)
111
+ - [Example page](../../example/react-native/pages/PerfMemoryTestPage.tsx)
112
+ - [Changelog](../../CHANGELOG.md)
56
113
 
57
114
  ## License
58
115
 
59
- MIT.
116
+ MIT. See [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-perf-memory",
3
- "version": "6.7.0-alpha.475",
3
+ "version": "6.8.0-10",
4
4
  "description": "Native process memory sampling for OneKey on iOS and Android",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -90,6 +90,7 @@
90
90
  "typescript": "^5.9.2"
91
91
  },
92
92
  "peerDependencies": {
93
+ "@onekeyfe/react-native-native-logger": "*",
93
94
  "react": "*",
94
95
  "react-native": "*",
95
96
  "react-native-nitro-modules": "0.37.0"