@rn-perf-kit/core 0.1.1 → 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/package.json +2 -1
- package/src/budgets.ts +6 -2
- package/src/timeline.ts +4 -3
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"
|
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 };
|