From 7ee040498685ce65e6a3513ed366a37e2d5cc1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 3 Dec 2026 17:18:33 +0100 Subject: [PATCH] test(performance): run the shared renderer Harness suite on iOS Release --- .github/workflows/ios-harness-smoke.yml | 61 +++++++++++++++++ scripts/performance/ios/README.md | 6 ++ scripts/performance/ios/harness/entry.tsx | 57 ++++++++++++++++ scripts/performance/ios/harness/run.py | 83 +++++++++++++++++++++++ scripts/performance/ios/harness/stage.py | 32 +++++++++ 5 files changed, 239 insertions(+) create mode 100644 .github/workflows/ios-harness-smoke.yml create mode 100644 scripts/performance/ios/harness/entry.tsx create mode 100644 scripts/performance/ios/harness/run.py create mode 100644 scripts/performance/ios/harness/stage.py diff --git a/.github/workflows/ios-harness-smoke.yml b/.github/workflows/ios-harness-smoke.yml new file mode 100644 index 000000000..f4273918d --- /dev/null +++ b/.github/workflows/ios-harness-smoke.yml @@ -0,0 +1,61 @@ +name: iOS Release Harness smoke + +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + smoke: + runs-on: xcode-27 + timeout-minutes: 90 + steps: + - uses: actions/checkout@v7 + with: + path: app + submodules: recursive + persist-credentials: false + + - name: Check out the shared mount and update workloads from PR 774 + uses: actions/checkout@v7 + with: + ref: 3c59941560a1a1077fe982df802f644b08205bf6 + path: workloads + sparse-checkout: scripts/performance/scenarios + persist-credentials: false + + - uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.4.4 + + - name: Build the Release example with the shared workloads + run: | + python3 app/scripts/performance/ios/harness/stage.py app workloads/scripts/performance/scenarios/render.tsx + cd app + bun install + cd apps/example + echo 'ARCHS = arm64' > "$RUNNER_TEMP/simulator.xcconfig" + export XCODE_XCCONFIG_FILE="$RUNNER_TEMP/simulator.xcconfig" + bun run nitro-ui ios --release --build-only > "$RUNNER_TEMP/build.log" 2>&1 || { tail -100 "$RUNNER_TEMP/build.log"; exit 1; } + + - name: Run both Harness tests three times on iOS 27 + run: | + device=$(xcrun simctl create "Nitro UI Harness" com.apple.CoreSimulator.SimDeviceType.iPhone-17 com.apple.CoreSimulator.SimRuntime.iOS-27-0) + trap 'xcrun simctl delete "$device"' EXIT + xcrun simctl bootstatus "$device" -b + app="app/apps/example/.nitro/build/Build/Products/Release-iphonesimulator/NitroUI Example.app" + test -f "$app/main.hbc" + id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$app/Info.plist") + xcrun simctl install "$device" "$app" + python3 app/scripts/performance/ios/harness/run.py "$device" "$id" "$RUNNER_TEMP/harness" + + - uses: actions/upload-artifact@v7 + if: always() + with: + name: ios-release-harness-${{ github.run_id }}-${{ github.run_attempt }} + path: | + ${{ runner.temp }}/harness/ + ${{ runner.temp }}/build.log + if-no-files-found: warn + retention-days: 7 diff --git a/scripts/performance/ios/README.md b/scripts/performance/ios/README.md index 60684124c..361729e63 100644 --- a/scripts/performance/ios/README.md +++ b/scripts/performance/ios/README.md @@ -17,3 +17,9 @@ The driver discards two warmup pairs, randomizes which arm launches first, then The job finishes the requested 16, 32, or 64 pairs. At each planned checkpoint it computes rank-based intervals with simultaneous 95% coverage across both metrics and all planned checkpoints, assuming independent blocks with a common median. It records when both intervals first fit within five percentage points of their respective estimated changes. That precision target is separate from the size of regression a maintainer considers acceptable. For example, an interval from −2% to +6% still allows a 5% slowdown. The Actions artifact contains `session.json` with revisions, launch order, host and simulator details, `raw.jsonl` with each launch, and `results.json` and `summary.md` with the checkpoint estimates. Each calibration and positive control has its own directory. Reported checkpoint time covers measured launches. Build, simulator boot, installation, and warmup also count toward CI latency. + +## Release Harness renderer smoke + +The manual **iOS Release Harness smoke** workflow launches the full example app three times on the same iPhone 17 simulator. Each fresh process runs the two React workloads from [PR #774](https://github.com/margelo/nitro-ui/pull/774). The first mounts 256 rows and checks every native label. The second keeps 64 views mounted through 31 renders and checks their identities and final properties. PerfKit 0.2.1 measures elapsed time and CPU time on the Hermes thread. Each launch produces a JSON report with its assertions, timings and compiled framework ID. + +The workflow checks out the workload at a pinned commit while the Android suite is in review. The staging script copies its TSX into a disposable checkout, updates the two pre-rename package imports, and selects it through the example Xcode target's entry. Three launches verify the integration. A regression estimate requires paired runs of two builds. diff --git a/scripts/performance/ios/harness/entry.tsx b/scripts/performance/ios/harness/entry.tsx new file mode 100644 index 000000000..3e3f0dbbd --- /dev/null +++ b/scripts/performance/ios/harness/entry.tsx @@ -0,0 +1,57 @@ +import 'nitro-ui-runtime' +import { useEffect } from 'react' +import { it } from 'nitro-ui-harness' +import { Application, renderRoot, ViewController, Window } from 'nitro-ui-renderer' +import { ThreadBenchmark, type ThreadBenchmarkResult } from '@callstack/performance-analytics-react-nitro' +import { finishCollection, resetCollection } from '../../../../packages/nitro-ui-harness/src/collect' +import { execute, serializeError } from '../../../../packages/nitro-ui-harness/src/execute' +import { cleanup, HarnessRoot } from '../../../../packages/nitro-ui-harness/src/render' +import { prepareMount, prepareUpdate } from './render' + +async function send(report: unknown) { + const body = JSON.stringify(report) + await fetch('http://127.0.0.1:19875/report', { method: 'POST', body: body }) +} + +async function run() { + const framework: unknown = Reflect.get(globalThis, '__nitroUIFramework') + if (__DEV__ || typeof framework !== 'object' || framework === null || !('id' in framework) || typeof framework.id !== 'string') { + throw new Error('Expected the compiled production Static Hermes framework') + } + const collected = resetCollection() + const windows: ThreadBenchmarkResult[] = [] + for (const [name, prepare] of [['mount', prepareMount], ['update', prepareUpdate]] as const) { + it(name, async () => { + const scenario = await prepare() + const timer = new ThreadBenchmark(name) + await scenario.run() + const result = timer.end() + await scenario.verify() + windows.push(result) + }) + } + finishCollection() + const tests: { name: string[], status: string, errors: unknown }[] = [] + const errors = await execute(collected, { + testNamePattern: undefined, testTimeout: 60000, + async onTestStart() {}, + async onTestResult(name, status, _, errors) { + tests.push({ name: name, status: status, errors: errors }) + }, + afterEachTest: cleanup, takeUncaughtErrors: () => [], + }) + await send({ frameworkId: framework.id, tests: tests, errors: errors, windows: windows }) +} + +function SmokeRoot() { + useEffect(() => { + run().catch((error: unknown) => send({ error: serializeError(error) })) + }, []) + return +} + +Application.registerRoot((scene) => { + const controller = new ViewController() + renderRoot(, controller) + return new Window(scene, controller) +}) diff --git a/scripts/performance/ios/harness/run.py b/scripts/performance/ios/harness/run.py new file mode 100644 index 000000000..391e87351 --- /dev/null +++ b/scripts/performance/ios/harness/run.py @@ -0,0 +1,83 @@ +"""Launch an installed Release benchmark three times and save its Harness results.""" + +import argparse +from http.server import BaseHTTPRequestHandler, HTTPServer +import json +from pathlib import Path +import subprocess +import time + + +class ReportHandler(BaseHTTPRequestHandler): + def do_POST(self): + if self.path != "/report": + self.send_error(404) + return + length = int(self.headers["Content-Length"]) + if length < 1 or length > 65536: + self.send_error(400) + return + payload = self.rfile.read(length) + self.server.result = json.loads(payload) + self.send_response(200) + self.end_headers() + + +def capture(server, device, bundle, log): + command = ["xcrun", "simctl", "launch", "--terminate-running-process", "--console", device, bundle] + server.result = None + with log.open("wb") as stream: + process = subprocess.Popen(command, stdout=stream, stderr=subprocess.STDOUT) + try: + deadline = time.monotonic() + 150 + while server.result is None and time.monotonic() < deadline and process.poll() is None: + server.handle_request() + finally: + subprocess.run(["xcrun", "simctl", "terminate", device, bundle], check=False, timeout=60) + process.wait(timeout=30) + if server.result is None: + raise RuntimeError(f"No report from {bundle}. See {log}.") + return server.result + + +def verify(report): + if report.get("error") or report["errors"]: + raise ValueError(f"Harness reported an error: {report}") + framework = report["frameworkId"] + if len(framework) != 64: + raise ValueError("Missing compiled Static Hermes framework identity") + tests = [(test["name"], test["status"], test["errors"]) for test in report["tests"]] + if tests != [(["mount"], "passed", []), (["update"], "passed", [])]: + raise ValueError(f"Expected both renderer workloads to pass: {tests}") + windows = report["windows"] + if [window["name"] for window in windows] != ["mount", "update"]: + raise ValueError("Missing or unexpected SDK timing windows") + if windows[0]["threadId"] != windows[1]["threadId"]: + raise ValueError("The workloads ran on different Hermes threads") + for window in windows: + if window["threadId"] <= 0 or window["elapsedMs"] <= 0 or window["threadCpuMs"] <= 0: + raise ValueError(f"Missing SDK thread timing: {window}") + if window["countersAvailable"] is not False: + raise ValueError(f"Unexpected simulator hardware counter availability: {window}") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("device", help="UDID of one booted simulator") + parser.add_argument("bundle", help="Installed example bundle identifier") + parser.add_argument("output", type=Path, help="New directory for launch logs and raw measurements") + args = parser.parse_args() + args.output.mkdir(parents=True, exist_ok=False) + with HTTPServer(("127.0.0.1", 19875), ReportHandler) as server: + server.timeout = 1 + for launch in range(1, 4): + log = args.output / f"launch-{launch}.log" + report = capture(server, args.device, args.bundle, log) + contents = json.dumps(report, indent=2, allow_nan=False) + (args.output / f"launch-{launch}.json").write_text(contents + "\n") + verify(report) + print(f"Launch {launch}: {report['windows']}", flush=True) + + +if __name__ == "__main__": + main() diff --git a/scripts/performance/ios/harness/stage.py b/scripts/performance/ios/harness/stage.py new file mode 100644 index 000000000..5a9afff4b --- /dev/null +++ b/scripts/performance/ios/harness/stage.py @@ -0,0 +1,32 @@ +"""Stage the shared renderer suite in an expendable example app checkout.""" + +import argparse +import hashlib +import json +from pathlib import Path +import shutil + +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument("checkout", type=Path) +parser.add_argument("workload", type=Path, help="The Android suite's scenarios/render.tsx") +args = parser.parse_args() +app = args.checkout / "apps/example" +destination = app / "src/performance" +destination.mkdir() +workload = args.workload.read_text() +# PR #774 predates the package rename. Stage its existing TSX bodies and assertions. +workload = workload.replace("'react-nitro-harness'", "'nitro-ui-harness'") +workload = workload.replace("'react-nitro-renderer'", "'nitro-ui-renderer'") +staged = destination / "render.tsx" +staged.write_text(workload) +entry = Path(__file__).with_name("entry.tsx") +shutil.copyfile(entry, destination / entry.name) +# The example Xcode target explicitly passes --entry src/index.tsx. +(app / "src/index.tsx").write_text("import './performance/entry'\n") +manifest = app / "package.json" +package = json.loads(manifest.read_text()) +package["dependencies"]["@callstack/performance-analytics-react-nitro"] = "0.2.1" +contents = json.dumps(package, indent=2) +manifest.write_text(contents + "\n") +digest = hashlib.sha256(staged.read_bytes()).hexdigest() +print(f"Staged mount/update workload SHA-256 {digest}")