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
140 changes: 140 additions & 0 deletions .github/workflows/android-performance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: Android performance (ADC)

on:
workflow_dispatch:
inputs:
baseline:
description: Baseline Git ref
default: main
required: true
candidate:
description: Candidate Git ref (defaults to the workflow revision)
workload:
description: Repository-relative Harness workload to embed in both apps
default: scripts/performance/workloads.tsx
thread_counters:
description: Measure hardware counters for the standard fixture at a fixed 64 pairs
type: boolean
default: false
pairs:
description: Maximum pairs for adaptive timing (even, at least 20)
default: '256'
required: true
precision:
description: Required precision for adaptive timing in percentage points
default: '5'
required: true
pull_request:

permissions: {}

jobs:
compare:
permissions:
contents: read
packages: read
if: github.event_name == 'workflow_dispatch' || (vars.ENABLE_ANDROID_PERFORMANCE == 'true' && github.event.pull_request.head.repo.full_name == github.repository)
runs-on: [self-hosted, linux, X64, hetzner-cx23]
timeout-minutes: 240
env:
CC: clang
CXX: clang++
CMAKE_BUILD_PARALLEL_LEVEL: 2
PAIRS: ${{ inputs.pairs || '256' }}
THREAD_COUNTERS: ${{ inputs.thread_counters && 'true' || 'false' }}
TARGET_PP: ${{ inputs.precision || '5' }}
WORKLOAD: ${{ inputs.workload || 'scripts/performance/workloads.tsx' }}
steps:
- uses: actions/checkout@v7
with:
path: experiment
persist-credentials: false

- uses: actions/checkout@v7
with:
ref: ${{ inputs.baseline || github.event.pull_request.base.sha }}
path: baseline
submodules: recursive
persist-credentials: false

- uses: actions/checkout@v7
with:
ref: ${{ inputs.candidate || github.event.pull_request.head.sha || github.sha }}
path: candidate
submodules: recursive
persist-credentials: false

- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.4

- uses: actions/setup-python@v6
with:
python-version: '3.10'

- uses: actions/setup-java@v6
with:
distribution: temurin
java-version: '17'

- name: Install Android build tools
run: |
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" 'platforms;android-36' 'ndk;29.0.14206865' 'cmake;3.22.1' platform-tools
echo "$ANDROID_HOME/platform-tools" >> "$GITHUB_PATH"

- name: Build the Release benchmark APK from each revision
env:
PERF_MAVEN_USER: ${{ github.actor }}
PERF_MAVEN_TOKEN: ${{ github.token }}
run: |
(cd experiment && bun install --frozen-lockfile --ignore-scripts)
for arm in baseline candidate; do
python3 experiment/scripts/performance/prepare.py "$arm" "$arm" --workload "experiment/$WORKLOAD"
(cd "$arm" && bun install && cd apps/example && bun run android --release --build-only --abi arm64-v8a)
metadata="$arm/apps/example/.nitro/android/apks/release.json"
id=$(jq -er .applicationId "$metadata")
test "$id" = "com.margelo.reactnitro.example.$arm"
apk=$(jq -er '.elements | select(length == 1) | .[0].outputFile' "$metadata")
debuggable=$("$ANDROID_HOME/cmdline-tools/latest/bin/apkanalyzer" manifest debuggable "$apk")
test "$debuggable" = false
cp "$apk" "$arm.apk"
done

- uses: margelo/adc@09956980c08fe6790198c721fc0a9da500778407 # v0.5.1
with:
api-key: ${{ secrets.ADC_API_KEY }}
name: React Nitro performance ${{ github.run_id }}-${{ github.run_attempt }}
form-factor: phone
api-level: '35'
width: '720'
height: '1600'
dpi: '320'
command: |
set -- --pairs "$PAIRS" --target-pp "$TARGET_PP"
if [ "$THREAD_COUNTERS" = true ]; then
set -- --pairs 64 --fixed --thread-counters
fi
python3 experiment/scripts/performance/run.py "$@" \
--baseline baseline baseline.apk --candidate candidate candidate.apk --output experiment/results

- name: Summarize paired changes
run: |
if [ "$THREAD_COUNTERS" = true ]; then
python3 experiment/scripts/performance/thread-counters/analyze_fixed.py --markdown experiment/results > experiment/results/report.md
else
python3 experiment/scripts/performance/analyze.py --session experiment/results/session.json experiment/results/raw.jsonl > experiment/results/report.md
fi
cat experiment/results/report.md >> "$GITHUB_STEP_SUMMARY"

- name: Save readings and SDK sessions to CI storage
if: ${{ !cancelled() && hashFiles('experiment/results/session.json') != '' }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CI_S3_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_S3_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: garage
AWS_ENDPOINT_URL_S3: ${{ vars.CI_S3_ENDPOINT_URL }}
CI_S3_BUCKET: ${{ vars.CI_S3_BUCKET }}
run: |
uri="s3://$CI_S3_BUCKET/runs/$GITHUB_RUN_ID/$GITHUB_RUN_ATTEMPT/performance/"
aws s3 cp experiment/results/ "$uri" --recursive --only-show-errors
echo "Raw measurements: \`$uri\`" >> "$GITHUB_STEP_SUMMARY"
16 changes: 16 additions & 0 deletions scripts/performance/BenchmarkSnapshot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.margelo.reactnitro.example

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Base64
import com.callstack.performanceanalytics.CallstackPerformanceAnalytics

class BenchmarkSnapshot : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val files = CallstackPerformanceAnalytics.readStoredPayloadFilesForDebug(context)
val session = files.current.singleOrNull() ?: return
val bytes = session.content.toByteArray(Charsets.UTF_8)
resultData = Base64.encodeToString(bytes, Base64.NO_WRAP)
}
}
Loading
Loading