Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .github/workflows/ios-performance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: iOS Simulator performance

on:
workflow_dispatch:
inputs:
baseline:
description: Baseline commit SHA (defaults to the workflow revision)
type: string
candidate:
description: Candidate commit SHA (defaults to the workflow revision)
type: string
pairs:
description: Measured launch pairs
type: choice
options: ['16', '32', '64']
default: '32'
positive_control:
description: Also measure 6.25% more candidate layout passes with the same pair count (identical revisions only)
type: boolean
default: false
pull_request:
paths:
- 'packages/nitro-ui-layout-yoga/**'
- 'packages/nitro-ui-layout/**'
- 'scripts/performance/ios/**'
- '.github/workflows/ios-performance.yml'

permissions:
contents: read

jobs:
compare:
if: github.event_name == 'workflow_dispatch' || vars.ENABLE_IOS_PERFORMANCE == 'true'
runs-on: macos-26-intel
timeout-minutes: 60
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || inputs.baseline || github.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || inputs.candidate || github.sha }}
PAIRS: ${{ inputs.pairs || '32' }}
CONTROL: ${{ inputs.positive_control || false }}
steps:
- name: Validate experiment inputs
shell: bash
run: |
[[ "$BASE_SHA" =~ ^[0-9a-f]{40}$ && "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]]
[[ "$PAIRS" =~ ^(16|32|64)$ ]]
if [[ "$CONTROL" == true && "$BASE_SHA" != "$HEAD_SHA" ]]; then
echo "The positive control requires two builds of the same commit." >&2
exit 1
fi

- name: Check out benchmark fixture and driver
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.base.sha || github.sha }}
path: control
persist-credentials: false
- name: Check out baseline
uses: actions/checkout@v7
with:
ref: ${{ env.BASE_SHA }}
path: baseline
persist-credentials: false
- name: Check out candidate
uses: actions/checkout@v7
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ env.HEAD_SHA }}
path: candidate
persist-credentials: false

- name: Build both Release simulator apps
run: |
control/scripts/performance/ios/build.sh baseline baseline "$RUNNER_TEMP/Baseline.app"
control/scripts/performance/ios/build.sh candidate candidate "$RUNNER_TEMP/Candidate.app"

- name: Boot iPhone 17 with iOS 26.5
id: simulator
run: |
device=$(xcrun simctl create "Nitro UI benchmark" com.apple.CoreSimulator.SimDeviceType.iPhone-17 com.apple.CoreSimulator.SimRuntime.iOS-26-5)
echo "device=$device" >> "$GITHUB_OUTPUT"
xcrun simctl bootstatus "$device" -b

- name: Compare paired launches
env:
DEVICE: ${{ steps.simulator.outputs.device }}
run: |
mkdir -p "$RUNNER_TEMP/performance"
{ sysctl hw.memsize vm.swapusage; vm_stat; df -h "$RUNNER_TEMP"; } > "$RUNNER_TEMP/performance/host-before.txt"
trap '{ sysctl hw.memsize vm.swapusage; vm_stat; df -h "$RUNNER_TEMP"; } > "$RUNNER_TEMP/performance/host-after.txt"' EXIT
compare() {
python3 control/scripts/performance/ios/compare.py \
--device "$DEVICE" --baseline "$RUNNER_TEMP/Baseline.app" --candidate "$RUNNER_TEMP/Candidate.app" \
--baseline-revision "$BASE_SHA" --candidate-revision "$HEAD_SHA" "$@"
}
compare --pairs "$PAIRS" --output "$RUNNER_TEMP/performance/comparison"
cat "$RUNNER_TEMP/performance/comparison/summary.md" >> "$GITHUB_STEP_SUMMARY"
if [[ "$CONTROL" == true ]]; then
compare --positive-control --pairs "$PAIRS" --output "$RUNNER_TEMP/performance/positive-control"
cat "$RUNNER_TEMP/performance/positive-control/summary.md" >> "$GITHUB_STEP_SUMMARY"
fi

- name: Upload measurements
if: always()
uses: actions/upload-artifact@v7
with:
name: ios-performance-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/performance
retention-days: 30
if-no-files-found: warn

- name: Delete simulator
if: always() && steps.simulator.outputs.device != ''
env:
DEVICE: ${{ steps.simulator.outputs.device }}
run: xcrun simctl delete "$DEVICE"
38 changes: 38 additions & 0 deletions scripts/performance/ios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# iOS Simulator performance

The [iOS Simulator performance workflow](../../../.github/workflows/ios-performance.yml) compares two Nitro UI commits on one standard GitHub-hosted Intel Mac (`macos-26-intel`). Start it manually with two full commit SHAs. Leave both blank to measure two builds of the same revision (A/A). Select the positive control with identical revisions to run a second comparison with eight extra layout passes in the candidate (+6.25% work).

Set the repository variable `ENABLE_IOS_PERFORMANCE=true` to run a comparison on pull requests touching the Yoga provider, layout interface, or benchmark. A PR uses the fixture and driver from its base revision. Each revision supplies its own production layout library. The workflow has read-only repository access. A successful check means the two apps produced valid measurements. The job summary shows the estimated change and its uncertainty.

## What one launch measures

The fixture mounts 32 rows of eight UIKit views. On the main thread it warms up the layout, opens PerfKit's `ThreadBenchmark`, changes all 256 leaf widths, solves with Nitro UI's Yoga provider, and applies the resulting frames. One sample covers 128 of these passes. It verifies the final geometry and the number of frame updates after closing the measurement window. The fixture compiles the released iOS timing implementation from PerfKit v0.2.1 using its pinned commit and SHA-256 digest.

Both apps are Release builds with different bundle IDs installed on one iPhone 17 simulator running iOS 26.5. The outputs are wall time and main-thread CPU time for the layout work. App launch, tree construction, and verification fall outside the timed section. The simulator executes on the Mac's CPU. Physical-iPhone frame pacing, GPU rendering, JavaScript, and hardware performance counters are outside this fixture's coverage.

## Reading the comparison

Each app writes its nonce and process ID with the result, then exits. The driver validates the result and waits for that process to exit before launching the next arm. A failed launch ends the experiment and leaves the completed samples in the artifact.

The driver discards two warmup pairs, randomizes which arm launches first, then alternates AB and BA. Each two-pair block yields an order-balanced log ratio. The report converts the median block ratio to a percentage change. Positive means the candidate took longer.

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.

## Calibration

Both apps used Nitro UI commit `9c13ee891421`. The table shows the change at 32 pairs with simultaneous 95% intervals. Each positive control added 6.25% more layout passes.

| Host and experiment | Measured launches | Wall-time change | Main-thread CPU change |
| --- | ---: | ---: | ---: |
| GitHub Intel, identical builds | 4m06s | −1.11% [−20.02%, +15.65%] | −0.54% [−8.85%, +6.78%] |
| GitHub Intel, positive control | 4m38s | +4.63% [−7.62%, +21.48%] | +8.48% [−0.61%, +19.13%] |
| GitHub ARM, identical builds | 1m56s | −7.44% [−15.28%, +11.62%] | −7.46% [−15.07%, +11.45%] |
| GitHub ARM, positive control | 1m37s | +6.23% [−4.21%, +16.05%] | +6.30% [−3.83%, +15.97%] |
| Local M2 Pro, identical builds | 2m39s | −0.63% [−2.74%, +1.82%] | −0.64% [−2.70%, +1.80%] |
| Local M2 Pro, positive control | 2m25s | +6.43% [+5.07%, +8.79%] | +6.43% [+5.11%, +8.84%] |

The Intel job waited 36m46s and took 24m21s to run both experiments. The ARM job used an iPhone 17 simulator on iOS 27.0, waited 1h43m for a runner and took 11m48s to run. At 32 pairs the hosted intervals still allowed both zero change and a 5% slowdown. The local simulator used iOS 27.0 on an iPhone 18 Pro device model. Both local comparisons reached the five-point precision target by 16 pairs. [Intel run](https://github.com/margelo/nitro-ui/actions/runs/47147452527) · [ARM run](https://github.com/margelo/nitro-ui/actions/runs/47147360586)

A second completed Intel comparison ran identical builds for 64 pairs in 9m01s of measured launches. Wall time was −1.78% [−15.25%, +4.23%]. Main-thread CPU time was +1.29% [−7.47%, +7.47%]. Wall time ruled out a 5% slowdown in that run. CPU time still allowed one, and neither metric reached a five-point interval radius. One earlier attempt stopped after three complete pairs when CoreSimulator exceeded its 60-second launch timeout. The repeat allowed 180 seconds for the launch command. No failed samples were retried or pooled. [64-pair result](https://github.com/margelo/nitro-ui/actions/runs/47164590706) · [Incomplete attempt](https://github.com/margelo/nitro-ui/actions/runs/47157888129)
38 changes: 38 additions & 0 deletions scripts/performance/ios/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# != 3 || ! $2 =~ ^(baseline|candidate)$ || $3 != *.app ]]; then
echo "Usage: $0 <nitro-ui-source-checkout> <baseline|candidate> <output.app>" >&2
exit 2
fi

source_root=$(cd "$1" && pwd)
fixture_dir=$(cd "$(dirname "$0")/fixture" && pwd)
revision=$(git -C "$source_root" rev-parse HEAD)
output=$3
if [[ -e "$output" ]]; then
echo "Output already exists: $output" >&2
exit 2
fi

git -C "$source_root" submodule update --init -- packages/nitro-ui-layout-yoga/yoga
scratch=$(mktemp -d)
trap 'rm -rf "$scratch"' EXIT

# Use the public SDK's standalone ThreadBenchmark at v0.2.1.
sdk_revision=d0f91e83bbe1be64efa3fd60a2a2253b553b5ff1
sdk_path=packages/react-native-sdk/apple/Sources/CallstackPerformanceAnalytics/ThreadBenchmark.swift
sdk_file="$scratch/ThreadBenchmark.swift"
curl --fail --silent --show-error --location --retry 3 \
"https://raw.githubusercontent.com/callstackincubator/performance-analytics/$sdk_revision/$sdk_path" -o "$sdk_file"
echo "f7c70f02647cc94580be84cc8ae256d21657f635c53453fc5f3e0bd9d0e28ee8 $sdk_file" | shasum -a 256 -c -

cmake -S "$fixture_dir" -B "$scratch/build" -G Xcode \
-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator \
-DCMAKE_OSX_ARCHITECTURES="$(uname -m)" -DCMAKE_OSX_DEPLOYMENT_TARGET=16.0 \
-DNITRO_SOURCE_ROOT="$source_root" -DTHREAD_BENCHMARK_SOURCE="$sdk_file" \
-DNITRO_REVISION="$revision" -DNITRO_VARIANT="$2"
cmake --build "$scratch/build" --config Release --target NitroPerf -- -quiet CODE_SIGNING_ALLOWED=NO
mkdir -p "$(dirname "$output")"
ditto "$scratch/build/app/NitroPerf.app" "$output"
codesign --force --sign - "$output"
Loading
Loading