@rn-perf-kit/core 0.1.0 → 0.1.2
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.
- package/README.md +25 -0
- package/package.json +22 -2
- package/src/budgets.ts +6 -2
- package/src/timeline.ts +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @rn-perf-kit/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@rn-perf-kit/core)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
> Core timeline, high-throughput ring buffer, unified event model, monotonic clock synchronization, and tier-aware budget engine for **rn-perf-kit**.
|
|
7
|
+
|
|
8
|
+
Part of the [rn-perf-kit](https://github.com/arpitkumarsahu/rn-perf-kit) monorepo.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @rn-perf-kit/core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Timeline & RingBuffer**: Pre-allocated fixed-capacity buffer that records up to 10,000 events with zero GC pressure on the hot path.
|
|
19
|
+
- **Monotonic Clock Sync**: Math that maps native nanosecond timestamps (from Android Choreographer and iOS CADisplayLink) onto JavaScript `performance.now()` with sub-millisecond precision.
|
|
20
|
+
- **Unified Event Model**: Typed unions covering renders, commits, frame metrics, stalls, layout effects, store actions, network requests, and route changes.
|
|
21
|
+
- **Budget Engine**: Evaluates metrics against hardware capability tiers (`LOW`, `MID`, `HIGH`).
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
Full guides and API reference are available at [github.com/arpitkumarsahu/rn-perf-kit](https://github.com/arpitkumarsahu/rn-perf-kit#readme).
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rn-perf-kit/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Core timeline, ring buffer, event model and budget engine for rn-perf-kit",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc --project tsconfig.build.json",
|
|
9
9
|
"typecheck": "tsc --noEmit",
|
|
10
|
+
"prepublishOnly": "npm run typecheck",
|
|
10
11
|
"lint": "eslint src/",
|
|
11
12
|
"test": "jest",
|
|
12
13
|
"clean": "rm -rf dist"
|
|
@@ -16,5 +17,24 @@
|
|
|
16
17
|
"@types/jest": "^29.0.0",
|
|
17
18
|
"jest": "^29.0.0",
|
|
18
19
|
"ts-jest": "^29.0.0"
|
|
19
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"author": "Arpit Kumar Sahu <aarpitkumarsahu99@gmail.com>",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/arpitkumarsahu/rn-perf-kit.git",
|
|
26
|
+
"directory": "packages/core"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/arpitkumarsahu/rn-perf-kit/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/arpitkumarsahu/rn-perf-kit#readme",
|
|
32
|
+
"keywords": [
|
|
33
|
+
"react-native",
|
|
34
|
+
"performance",
|
|
35
|
+
"timeline",
|
|
36
|
+
"ring-buffer",
|
|
37
|
+
"clock-sync",
|
|
38
|
+
"budgets"
|
|
39
|
+
]
|
|
20
40
|
}
|
package/src/budgets.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Budgets are tier-aware: LOW / MID / HIGH device classifications.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { perfClock } from './clock';
|
|
7
|
+
|
|
6
8
|
export type DeviceTier = 'LOW' | 'MID' | 'HIGH';
|
|
7
9
|
|
|
8
10
|
export interface TieredBudget {
|
|
@@ -86,14 +88,16 @@ export class BudgetEngine {
|
|
|
86
88
|
if (budget === undefined) return null;
|
|
87
89
|
if (type !== 'fps' && actual <= budget) return null;
|
|
88
90
|
|
|
91
|
+
const unit = type === 'fps' ? 'fps' : type === 'dropped-frames' ? '%' : 'ms';
|
|
92
|
+
const op = type === 'fps' ? '<' : '>';
|
|
89
93
|
const violation: BudgetViolation = {
|
|
90
94
|
type,
|
|
91
95
|
budget,
|
|
92
96
|
actual,
|
|
93
97
|
tier: this.tier,
|
|
94
98
|
route: budgetKey,
|
|
95
|
-
message: `[${type}]${budgetKey ? ` ${budgetKey}` : ''} ${actual.toFixed(0)}
|
|
96
|
-
t: t ??
|
|
99
|
+
message: `[${type}]${budgetKey ? ` ${budgetKey}` : ''} ${actual.toFixed(0)}${unit} ${op} budget ${budget}${unit} (tier: ${this.tier})`,
|
|
100
|
+
t: t ?? perfClock.jsNow(),
|
|
97
101
|
};
|
|
98
102
|
this.violations.push(violation);
|
|
99
103
|
this.onViolation?.(violation);
|
package/src/timeline.ts
CHANGED
|
@@ -16,11 +16,12 @@ export interface TimelineOptions extends RingBufferOptions {
|
|
|
16
16
|
class Timeline {
|
|
17
17
|
private buffer: RingBuffer;
|
|
18
18
|
private listeners = new Map<PerfEventType | '*', Set<EventListener>>();
|
|
19
|
-
|
|
19
|
+
// Default to false: zero overhead until PerfProvider explicitly enables it
|
|
20
|
+
private _enabled = false;
|
|
20
21
|
|
|
21
22
|
constructor(options: TimelineOptions = {}) {
|
|
22
23
|
this.buffer = new RingBuffer(options);
|
|
23
|
-
this._enabled = options.enabled ??
|
|
24
|
+
this._enabled = options.enabled ?? false;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
get enabled(): boolean {
|
|
@@ -80,5 +81,5 @@ class Timeline {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
export const timeline = new Timeline();
|
|
84
|
+
export const timeline = new Timeline({ enabled: false });
|
|
84
85
|
export type { Timeline };
|