@parallax-rn/perf-native 0.0.0-stage → 0.1.0-beta.3

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/LICENSE ADDED
@@ -0,0 +1,72 @@
1
+ PARALLAX LICENSE (BETA TERMS, VERSION 1, 2026-10-28)
2
+
3
+ Copyright (c) 2026 Valiantsin Tsikhamirau. All rights reserved.
4
+ Contact: zemantservices@gmail.com, https://parallax-rn.dev
5
+
6
+ 1. Definitions
7
+ "Software" means this package of Parallax for React Native, including its code, documentation and any updates the Licensor supplies. "You" means the person or
8
+ organization that installs or uses the Software. "Licensor" means Valiantsin Tsikhamirau, the author of the Software. "Your Applications" means software that You
9
+ develop or maintain.
10
+
11
+ 2. Grant of license
12
+ The Licensor grants You a worldwide, non-exclusive, non-transferable, revocable, royalty-free license, free of charge, to install and use the Software
13
+ for Your own personal or internal business purposes, including the commercial development, testing and debugging of Your Applications. This includes:
14
+ (a) adding the in-app SDK and the Babel plugin of the Software to Your Applications as development dependencies;
15
+ (b) building, distributing and selling Your Applications, even when a build of Your Application contains code of the SDK or of the Babel plugin, as long
16
+ as that code stays a part of Your Application and is not offered on its own;
17
+ (c) keeping copies of the Software in Your organization's internal package mirrors, registries, caches, continuous integration systems, lock files and
18
+ vendored dependency folders, for use under this license by Your own staff and contractors;
19
+ (d) installing it on any number of machines used by You, Your staff or Your contractors working on Your Applications.
20
+
21
+ 3. Restrictions
22
+ Except as this license expressly allows or as mandatory law allows despite this limit, You may not:
23
+ (a) modify, adapt, translate or create derivative works of the Software;
24
+ (b) distribute, sublicense, sell, rent, lease, lend, host as a service or otherwise make the Software or any part of it available to others outside Your
25
+ organization, including by publishing it to a public package registry or repository, except as section 2 allows;
26
+ (c) reverse engineer, decompile or disassemble the Software, or try to obtain its source code;
27
+ (d) use the Software, its output or its documentation to build, train or benchmark a product or service that competes with the Software, or give the
28
+ Software to a person for that purpose;
29
+ (e) remove or change any copyright, license or other notice in the Software.
30
+
31
+ 4. Third-party components
32
+ The Software contains third-party components under their own licenses, listed in the file THIRD_PARTY_NOTICES where the package contains one. Those licenses,
33
+ not this one, govern those components.
34
+
35
+ 5. Ownership
36
+ The Software is licensed, not sold. The Licensor keeps all rights not expressly granted. This license grants no right to the Licensor's name or marks.
37
+ Your Applications, their data and the output of Your agents stay Yours.
38
+
39
+ 6. Data
40
+ The Software runs on Your machine. It has no account, no telemetry and no analytics, and it does not send data to the Licensor. What it reads from Your
41
+ application and simulator or emulator (the screen, the component tree, logs, errors, network requests, state and navigation) is returned to the AI agent
42
+ You connect to it, such as Claude Code or Codex, and that agent sends what it receives to its own provider under that provider's terms. The Licensor does
43
+ not control that. The Software removes known secrets from network and state data before an agent receives them; logs and errors are passed on as Your
44
+ application wrote them.
45
+
46
+ 7. Beta software
47
+ The Software is a beta. It may change, stop working or be withdrawn at any time, and later versions may come under different terms, including paid terms
48
+ for some parts. A version You received under this license stays under this license.
49
+
50
+ 8. Termination
51
+ This license ends automatically if You breach it. Then You must stop using the Software and delete all copies, except copies inside builds of Your
52
+ Applications that section 2(b) allows. You may end it at any time by deleting the Software. Sections 3, 5, 9, 10 and 11 survive.
53
+
54
+ 9. No warranty
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
56
+ PURPOSE AND NON-INFRINGEMENT.
57
+
58
+ 10. Limitation of liability
59
+ TO THE EXTENT THE LAW ALLOWS, THE LICENSOR IS NOT LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES, OR FOR LOST PROFITS OR DATA,
60
+ ARISING FROM THE SOFTWARE OR ITS USE, AND THE LICENSOR'S TOTAL LIABILITY IS LIMITED TO THE AMOUNT YOU PAID FOR THE SOFTWARE (ZERO FOR THE FREE LICENSE).
61
+ NOTHING IN THIS LICENSE LIMITS LIABILITY FOR INTENT OR GROSS NEGLIGENCE, OR ANY LIABILITY THAT CANNOT BE LIMITED BY LAW.
62
+
63
+ 11. General
64
+ (a) Governing law and courts. This license is governed by the law of the Republic of Belarus, without regard to its conflict of laws rules. The courts of
65
+ Minsk, Belarus, have jurisdiction over any dispute about it. If You are a consumer, nothing in this license takes away a protection that the law of the
66
+ country where You live gives You and that cannot be waived by agreement, including Your right to bring a claim in Your own courts.
67
+ (b) Severability. If a court finds a part of this license invalid, that part is limited to the minimum extent needed and the rest stays in force.
68
+ (c) Entire agreement. This license is the entire agreement between You and the Licensor about the Software and replaces any earlier statement about it.
69
+ A paid tier, if one is offered later, comes with its own terms.
70
+ (d) Export. You must comply with the export control and sanctions laws that apply to You when You use or move the Software.
71
+ (e) No waiver. If the Licensor does not enforce a term, the Licensor keeps the right to enforce it later.
72
+ (f) Language. This license is written in English; a translation is for convenience only.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @parallax-rn/perf-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The optional iOS add-on of Parallax's performance monitor (plan 0017, decision 0024). It gives the monitor the exact frame times of the UI thread, which iOS offers a simulator app no other way. Without it the monitor says the iOS UI frame rate needs this package and shows no number. Android needs nothing (the system's `dumpsys gfxinfo` is read from outside).
4
+
5
+ **Status: built and checked on a device (2026-10-28):** a Debug build of a fixture on the iOS simulator read about 60 frames a second, and a 300 ms block of the JS thread left them untouched (plan 0017). Not checked live: a main-thread block, a Release build (covered by the `RCT_DEV` guard and its test).
6
+
7
+ ## Install
8
+ ```bash
9
+ npm install -D @parallax-rn/perf-native@<version> # the same version as the server
10
+ cd ios && pod install
11
+ ```
12
+ In the app entry, next to the SDK: `if (__DEV__) { require('@parallax-rn/perf-native'); }`. Rebuild the app. Autolinking finds `perf-native.podspec`; there is no Android folder, so Android autolinking skips the package (`react-native.config.js` also says `android: null`).
13
+
14
+ ## What it is
15
+ - `ios/ParallaxPerf.m`: a legacy native module (`RCT_EXPORT_MODULE`, name `ParallaxPerf`) with three blocking synchronous methods, `start`, `stop` and `read:(double)sinceMs`. A `CADisplayLink` on the main run loop (common modes, so frames while scrolling count) stores `link.timestamp` in ms (`CACurrentMediaTime` clock) in a ring of 2,000 frames, and the screen's `maximumFramesPerSecond` is kept as the refresh rate.
16
+ - `src/`: the JS side. Importing the package installs `globalThis.__PARALLAX_PERF_NATIVE__ = { start(), stop(), read(sinceMs) }`. `read` returns `{ frames: number[], refreshRate: number, now: number }`; `now` is the native clock at the call (not in the first draft of the plan: the caller needs it to line the frames up with its own clock). Every answer is copied into plain numbers, and a failing or malformed native answer becomes an empty reading.
17
+ - It measures the main thread's frame rate, the same quantity as the "UI" number of React Native's own perf monitor. An animation that Core Animation renders by itself (a native-driver animation) stays smooth when the main thread is blocked and this number drops; the monitor's JS and React rows say why.
18
+
19
+ ## Why a legacy module
20
+ React Native 0.85 and later (bridgeless, new architecture only) still serves a legacy module and its `RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD` methods through the TurboModule interop layer (read in `react-native@0.86.3`: `RCTTurboModuleManager.mm` registers modules found by `RCT_EXPORT_MODULE`, `RCTInteropTurboModule.mm` calls a method that returns a value synchronously and converts the returned `NSDictionary`; `NativeModules` is `global.nativeModuleProxy` there). A real TurboModule would need a codegen spec, C++ and a `codegenConfig`, which is more machinery than three methods are worth; the cost is that the interop layer may log a legacy-architecture warning when the flag for it is on. Moving to a TurboModule later changes nothing for the caller.
21
+
22
+ ## Why a release build is untouched
23
+ 1. The JS side installs only when `__DEV__ === true`, and `require('react-native')` happens after that check, so a release bundle never reads the module (and Metro drops the `if (__DEV__)` line from the app entry).
24
+ 2. The native module does nothing at load or init. `start` creates the display link, and only `#if RCT_DEV` (React Native's own switch, on only when `DEBUG` is defined, i.e. a Debug configuration); otherwise `start` returns `NO` and no link ever exists.
25
+ 3. The library is linked into Release builds like any pod (a small object file, no code runs).
26
+ Tests that fail without these: `src/install.test.ts` (JS guard) and `src/package.test.ts` (the `RCT_DEV` guard and that only `start` creates the link).
27
+
28
+ ## Limits
29
+ - Timestamps come from the display link, so a frame the main thread never got to is a gap, not a number. A ProMotion iPhone needs `CADisableMinimumFrameDurationOnPhone` in `Info.plist` to run above 60; the simulator runs at 60.
30
+ - No data while the app is in the background (the system pauses the link).
31
+ - The ring keeps 2,000 frames (about 33 s at 60, 17 s at 120); the caller reads often and passes the last timestamp it saw as `sinceMs`.
32
+
33
+ ## To check with a native build (the lead's gate)
34
+ See the plan's step note: build the fixture with this package, `pod install` resolves `perf-native`, the app launches with no red box, `NativeModules.ParallaxPerf` exists under bridgeless, `read(0)` returns frames at about 60 a second on the simulator after `start()`, a 300 ms JS block does not create a gap (the main thread is free) while a main-thread block does, a Release build has no display link (`start()` answers false and `read` stays empty).
@@ -0,0 +1,4 @@
1
+ import { install } from './install';
2
+ export { install };
3
+ export type { NativeModule, NativeReading, PerfHost, PerfNative } from './install';
4
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.install = void 0;
5
+ // Add `if (__DEV__) require('@parallax-rn/perf-native');` to the app's entry file. Importing this module installs the binding (see install.ts); in a
6
+ // release build it does nothing. react-native is required only after the __DEV__ check, so a release bundle never loads anything from here.
7
+ const install_1 = require("./install");
8
+ Object.defineProperty(exports, "install", { enumerable: true, get: function () { return install_1.install; } });
9
+ const host = globalThis;
10
+ if (host.__DEV__ === true) {
11
+ let native;
12
+ try {
13
+ native = (_a = require('react-native').NativeModules) === null || _a === void 0 ? void 0 : _a.ParallaxPerf;
14
+ }
15
+ catch {
16
+ // no react-native (a Node test or an unusual host): there is nothing to install
17
+ }
18
+ (0, install_1.install)(host, native);
19
+ }
@@ -0,0 +1,28 @@
1
+ /** What the native module (ios/ParallaxPerf.m) answers to `read`. */
2
+ export interface NativeReading {
3
+ frames: number[];
4
+ refreshRate: number;
5
+ now: number;
6
+ }
7
+ export interface NativeModule {
8
+ start(): boolean;
9
+ stop(): unknown;
10
+ read(sinceMs: number): unknown;
11
+ }
12
+ export interface PerfNative {
13
+ /** true when the display link was asked for; false in a build that is not a development build */
14
+ start(): boolean;
15
+ stop(): void;
16
+ /** frame times in ms (CACurrentMediaTime) later than `sinceMs`, the screen's maximum frame rate, and `now` on the same clock; never throws */
17
+ read(sinceMs?: number): NativeReading;
18
+ }
19
+ export interface PerfHost {
20
+ __DEV__?: boolean;
21
+ __PARALLAX_PERF_NATIVE__?: PerfNative;
22
+ }
23
+ /**
24
+ * Installs the binding when this is a development build and the native module is linked; returns whether it did. In a release build (`__DEV__` not
25
+ * true) and without the native module it does nothing, so the core can tell "add-on not installed" from "installed".
26
+ */
27
+ export declare function install(host: PerfHost, native: NativeModule | undefined | null): boolean;
28
+ //# sourceMappingURL=install.d.ts.map
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ // The JS side of the iOS add-on. It publishes the native module on `globalThis.__PARALLAX_PERF_NATIVE__`, where the Parallax core finds it with
3
+ // Runtime.evaluate. Everything goes through the arguments (never ambient globals) so it is tested without React Native.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.install = install;
6
+ const empty = () => ({ frames: [], refreshRate: 0, now: 0 });
7
+ // The native side is ours, but the answer crosses the bridge: copy it into plain numbers so a wrong shape cannot reach the caller.
8
+ function sanitize(value) {
9
+ const raw = value;
10
+ if (!raw || !Array.isArray(raw.frames))
11
+ return empty();
12
+ const frames = [];
13
+ for (let i = 0; i < raw.frames.length; i++) {
14
+ const frame = raw.frames[i];
15
+ if (typeof frame === 'number' && isFinite(frame))
16
+ frames.push(frame);
17
+ }
18
+ const number = (v) => (typeof v === 'number' && isFinite(v) ? v : 0);
19
+ return { frames, refreshRate: number(raw.refreshRate), now: number(raw.now) };
20
+ }
21
+ /**
22
+ * Installs the binding when this is a development build and the native module is linked; returns whether it did. In a release build (`__DEV__` not
23
+ * true) and without the native module it does nothing, so the core can tell "add-on not installed" from "installed".
24
+ */
25
+ function install(host, native) {
26
+ if (host.__DEV__ !== true || !native)
27
+ return false;
28
+ host.__PARALLAX_PERF_NATIVE__ = {
29
+ start: () => {
30
+ try {
31
+ return native.start() === true;
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ },
37
+ stop: () => {
38
+ try {
39
+ native.stop();
40
+ }
41
+ catch {
42
+ // nothing to stop
43
+ }
44
+ },
45
+ read: (sinceMs = 0) => {
46
+ try {
47
+ return sanitize(native.read(sinceMs));
48
+ }
49
+ catch {
50
+ return empty();
51
+ }
52
+ },
53
+ };
54
+ return true;
55
+ }
@@ -0,0 +1,125 @@
1
+ // The iOS frame counter of Parallax's performance monitor (plan 0017, decision 0024): a CADisplayLink on the main run loop that stores the time of every
2
+ // frame it is called for. It is the main thread's frame rate, the same quantity as the "UI" number of React Native's own perf monitor.
3
+ //
4
+ // A legacy module (RCT_EXPORT_MODULE) with blocking synchronous methods: React Native 0.85 and later (bridgeless) still serves these through its
5
+ // TurboModule interop layer, so the package needs no codegen spec and no C++. The JS side reads it as NativeModules.ParallaxPerf.
6
+ #import <QuartzCore/QuartzCore.h>
7
+ #import <UIKit/UIKit.h>
8
+ #import <React/RCTBridgeModule.h>
9
+ #import <React/RCTDefines.h>
10
+ #import <React/RCTInvalidating.h>
11
+
12
+ #define PARALLAX_PERF_RING 2000
13
+
14
+ @interface ParallaxPerf : NSObject <RCTBridgeModule, RCTInvalidating>
15
+ @end
16
+
17
+ @implementation ParallaxPerf {
18
+ CADisplayLink *_link; // touched on the main thread only
19
+ NSLock *_lock; // guards everything below: tick runs on the main thread, read on the JS thread
20
+ double _ring[PARALLAX_PERF_RING];
21
+ NSUInteger _head;
22
+ NSUInteger _count;
23
+ double _refreshRate;
24
+ }
25
+
26
+ RCT_EXPORT_MODULE(ParallaxPerf)
27
+
28
+ + (BOOL)requiresMainQueueSetup
29
+ {
30
+ return NO;
31
+ }
32
+
33
+ - (instancetype)init
34
+ {
35
+ if ((self = [super init])) {
36
+ _lock = [NSLock new];
37
+ }
38
+ return self;
39
+ }
40
+
41
+ // Nothing runs until start is called, and start does nothing outside a development build (RCT_DEV is React Native's own switch, on only when DEBUG is
42
+ // defined), so a release build never creates a display link even if the JS side were called.
43
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(start)
44
+ {
45
+ #if RCT_DEV
46
+ dispatch_async(dispatch_get_main_queue(), ^{
47
+ [self startOnMain];
48
+ });
49
+ return @YES;
50
+ #else
51
+ return @NO;
52
+ #endif
53
+ }
54
+
55
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(stop)
56
+ {
57
+ dispatch_async(dispatch_get_main_queue(), ^{
58
+ [self stopOnMain];
59
+ });
60
+ return @YES;
61
+ }
62
+
63
+ // frames: the timestamps (ms, CACurrentMediaTime) later than sinceMs, oldest first. now: the same clock at the moment of the call, so the caller can
64
+ // line the frames up with its own clock.
65
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(read:(double)sinceMs)
66
+ {
67
+ NSMutableArray<NSNumber *> *frames = [NSMutableArray new];
68
+ [_lock lock];
69
+ NSUInteger first = (_head + PARALLAX_PERF_RING - _count) % PARALLAX_PERF_RING;
70
+ for (NSUInteger i = 0; i < _count; i++) {
71
+ double ts = _ring[(first + i) % PARALLAX_PERF_RING];
72
+ if (ts > sinceMs) {
73
+ [frames addObject:@(ts)];
74
+ }
75
+ }
76
+ double rate = _refreshRate;
77
+ [_lock unlock];
78
+ return @{@"frames" : frames, @"refreshRate" : @(rate), @"now" : @(CACurrentMediaTime() * 1000.0)};
79
+ }
80
+
81
+ - (void)invalidate
82
+ {
83
+ // the app is reloading or closing: the link retains this object, so it must go (invalidate may come on any thread)
84
+ dispatch_async(dispatch_get_main_queue(), ^{
85
+ [self stopOnMain];
86
+ });
87
+ }
88
+
89
+ - (void)startOnMain
90
+ {
91
+ if (_link != nil) {
92
+ return;
93
+ }
94
+ double max = (double)[UIScreen mainScreen].maximumFramesPerSecond;
95
+ [_lock lock];
96
+ _head = 0;
97
+ _count = 0;
98
+ _refreshRate = max;
99
+ [_lock unlock];
100
+ _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick:)];
101
+ if (@available(iOS 15.0, *)) {
102
+ // without this a ProMotion screen may be given a lower rate and the number would not be the screen's
103
+ _link.preferredFrameRateRange = CAFrameRateRangeMake(max, max, max);
104
+ }
105
+ [_link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; // common modes: frames while scrolling count too
106
+ }
107
+
108
+ - (void)stopOnMain
109
+ {
110
+ [_link invalidate];
111
+ _link = nil;
112
+ }
113
+
114
+ - (void)tick:(CADisplayLink *)link
115
+ {
116
+ [_lock lock];
117
+ _ring[_head] = link.timestamp * 1000.0;
118
+ _head = (_head + 1) % PARALLAX_PERF_RING;
119
+ if (_count < PARALLAX_PERF_RING) {
120
+ _count++;
121
+ }
122
+ [_lock unlock];
123
+ }
124
+
125
+ @end
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@parallax-rn/perf-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-beta.3",
4
+ "description": "Optional iOS add-on for Parallax for React Native: the UI thread's exact frame times (CADisplayLink) for the performance monitor. Dev builds only, no third-party dependencies. Not yet built on a device.",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "!dist/**/*.test.*",
11
+ "!dist/*.tsbuildinfo",
12
+ "!dist/**/*.map",
13
+ "ios",
14
+ "perf-native.podspec",
15
+ "react-native.config.js"
16
+ ],
17
+ "engines": {
18
+ "node": "^20.19.4 || ^22.13.0 || ^24.3.0 || >=25.0.0"
19
+ },
20
+ "peerDependencies": {
21
+ "react-native": ">=0.85.0"
22
+ },
23
+ "peerDependenciesMeta": {
24
+ "react-native": {
25
+ "optional": true
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'perf-native'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.homepage = 'https://www.npmjs.com/package/@parallax-rn/perf-native'
10
+ s.license = { :type => 'Proprietary', :file => 'LICENSE' }
11
+ s.author = 'Parallax'
12
+ s.platforms = { :ios => '15.1' }
13
+ s.source = { :path => '.' }
14
+ s.source_files = 'ios/**/*.{h,m}'
15
+
16
+ # install_modules_dependencies adds React-Core and whatever the app's architecture needs; the fallback is for a React Native without it
17
+ if respond_to?(:install_modules_dependencies, true)
18
+ install_modules_dependencies(s)
19
+ else
20
+ s.dependency 'React-Core'
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ // iOS only: Android reads frame times from the system (dumpsys gfxinfo), so this package has no android folder and is not linked there.
2
+ module.exports = {
3
+ dependency: {
4
+ platforms: {
5
+ android: null,
6
+ },
7
+ },
8
+ };