Skip to content

Conversation

@littlesmilelove
Copy link
Contributor

PR 说明:Perf Regression Guard(Detox + performance-server)

TL;DR(这次 PR 做了什么)

我们在仓库内落地了一套“自动化性能回归守护”的基础设施,用 Detox 作为编排器,在固定测试设备上重复跑基准场景,并基于 perf sessions(performance-server)做聚合与阈值判断,超阈值/失败时可发 Slack 告警。

覆盖平台:

  • iOS Simulator:Debug / Release
  • Android Emulator:Debug / Release

核心产物:

  • 一套可直接运行的命令:yarn perf:*
  • 一套可配置的阈值文件:development/perf-ci/thresholds/*
  • perf sessions 总览索引:$HOME/perf-sessions/sessions.overview.jsonl

PR 范围

  • 基线分支:x(base:origin/x
  • PR 分支:xeon/perf-regression-guard-ios-detox
  • 合入形式:1 个 commit(squash)
  • 主要目录:
    • development/perf-ci/(runner + docs + launchd 模板 + thresholds)
    • apps/mobile/e2e/(Detox Jest 测试 + Metro warmup)
    • apps/mobile/.detoxrc.js(iOS/Android Detox 配置)
    • development/performance-server/(health + session overview)

背景与目标

背景可参考:development/output/perf-regression-guard-ios-detox.md

我们已经有一套 perf 数据采集/落盘能力:

  • App 端采集:packages/shared/src/performance/*
  • 服务端落盘与分析:development/performance-server/*

缺口在于:缺少“可持续、可重复、自动化”的基准跑测与回归预警机制。

本 PR 的目标:

  1. 提供一条命令即可跑完的 one-shot runner(Debug/Release 各一套)
  2. 默认每次跑 3 轮,降低噪声(median 聚合)
  3. 输出结构化 report 便于长期对比
  4. 支持定时(launchd 模板)与可选 Slack Webhook 告警

总体设计

1) performance-server(常驻)

  • 启动:yarn perf:server
  • 默认输出目录:$HOME/perf-sessions
  • 新增 /api/health(runner 用来做健康检查与 outputDir 一致性校验)
  • 新增 sessions.overview.jsonl
    • perf-server 在 WebSocket 断开(session 结束)时,写入一条 session 概览记录(JSONL)

2) Detox e2e(单测负责 3-run loop)

Jest 测试:apps/mobile/e2e/perf-regression-guard.test.js

每轮 run:

  1. device.launchApp({ newInstance: true })
  2. 通过文件系统增量识别本次新增的 sessionId 目录
  3. 监听 <sessionId>/mark.log,等待 mark:Home:refresh:done:tokens
  4. 等待 AFTER_MARK_DELAY_MS 收尾,再 device.terminateApp()

Debug 模式:

  • apps/mobile/e2e/globalSetup.js 会做 Metro ready + warmup bundling(避免首次 bundle 太慢导致 app 侧报 “Could not connect to development server”)
  • Android Debug 额外做 reverseTcpPort(8081)(设备侧 localhost:8081 -> 宿主机 8081)

3) perf-ci job runner(负责构建/跑测/derive/阈值/Slack)

iOS:

  • development/perf-ci/run-ios-perf-detox-debug.js
  • development/perf-ci/run-ios-perf-detox-release.js
  • development/perf-ci/run-ios-perf-detox-release-daemon.js(interval daemon)

Android:

  • development/perf-ci/run-android-perf-detox-debug.js
  • development/perf-ci/run-android-perf-detox-release.js
  • development/perf-ci/run-android-perf-detox-release-daemon.js(interval daemon)

runner 负责:

  • 清理 Metro/watchman 缓存(降低环境污染)
  • Debug 模式下抢占 8081(保证可重复启动 Metro)
  • 检测/自动拉起 perf-server(one-shot 模式下跑完会自动关闭)
  • Android:若当前没有 emulator 在线,自动启动 AVD,并等待 boot complete
  • 运行 Detox(并读取 runs.json
  • 对每个 session 运行 derive:development/performance-server/cli/derive-session.js
  • 聚合 + 阈值判断 +(可选)Slack 通知

指标与阈值(当前实现)

阈值文件:

  • iOS Debug:development/perf-ci/thresholds/ios.debug.json
  • iOS Release:development/perf-ci/thresholds/ios.release.json
  • Android Debug:development/perf-ci/thresholds/android.debug.json
  • Android Release:development/perf-ci/thresholds/android.release.json

当前用于回归判断的指标(MVP):

  • tokensStartMsHome:refresh:start:tokens 的 timestamp
  • tokensSpanMsHome:refresh:done:tokens - Home:refresh:start:tokens
  • functionCallCountfunction_call.log 行数

策略:

  • 默认 strategy=median(3 次 run 取 median,大于阈值则触发 regression)
  • 可选 two_of_three

如何运行(本地/CI/定时)

详细使用说明见:development/perf-ci/README.md

常用命令(repo root):

# server
yarn perf:server

# iOS
yarn perf:ios:debug
yarn perf:ios:release
yarn perf:ios:release:daemon --interval-minutes 300

# Android
yarn perf:android:debug
yarn perf:android:release
yarn perf:android:release:daemon --interval-minutes 300

常用环境变量:

  • PERF_SESSIONS_DIR(默认:$HOME/perf-sessions
  • PERF_SERVER_URL(默认:http://localhost:9527,仅用于 health check / 启停 server)
  • SLACK_WEBHOOK_URL(可选)
  • DETOX_DEVICE_UDID(推荐 pin iOS simulator)
  • DETOX_ANDROID_AVD_NAME(推荐 pin Android AVD)

可选本地配置文件(避免 env vars):

  • development/perf-ci/config.local.json(已 gitignore)

定时任务(launchd)

本 PR 提供模板:

  • development/perf-ci/launchd/perf-server.plist:常驻 perf-server
  • development/perf-ci/launchd/ios-perf-job.plist:定时跑 iOS job

安装方式与注意事项写在:development/perf-ci/README.md

Android 定时:

  • 可参考 ios-perf-job.plist 复制一份,将 ProgramArguments 改为 yarn perf:android:release --headless

输出与排查

Perf sessions:

  • $HOME/perf-sessions/<sessionId>/...
  • $HOME/perf-sessions/sessions.overview.jsonl(session 概览索引)

Job 输出:

  • development/perf-ci/output/<jobId>/report.json
  • development/perf-ci/output/<jobId>/derived/*.json
  • development/perf-ci/output/<jobId>/detox/runs.json
  • (若 runner 启动了 perf-server/emu)对应 log 也会写到 job output 目录

备注与限制(当前假设)

  • PERF_SESSIONS_DIR 目录默认假设“单机串行写入”。如果并行跑多个 job 并写到同一个目录,可能会导致 sessionId 误匹配(需要后续增强:加 platform 校验/更强的 session 归属判定)。
  • Debug runner 会清理/抢占 Metro 8081(为了确定性);不建议在开发机上与其它 Metro 并行使用同端口。

- Add iOS/Android Detox configs and e2e perf regression test (3-run loop)

- Add perf-ci runners (debug/release/daemon), thresholds, Slack notification

- Improve performance-server: /api/health, session overview index

- Add docs and launchd templates
@revan-zhang
Copy link
Contributor

revan-zhang commented Jan 22, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@littlesmilelove littlesmilelove changed the title Xeon/perf regression guard ios detox perf regression guard ios detox Jan 22, 2026
@littlesmilelove littlesmilelove changed the title perf regression guard ios detox perf regression guard detox Jan 22, 2026
@socket-security
Copy link

socket-security bot commented Jan 22, 2026

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

@huhuanming huhuanming marked this pull request as draft January 22, 2026 10:53
@huhuanming huhuanming marked this pull request as ready for review January 29, 2026 10:59
@huhuanming huhuanming enabled auto-merge (squash) January 29, 2026 11:00
auto-merge was automatically disabled January 29, 2026 15:02

Head branch was pushed to by a user without write access

@originalix
Copy link
Collaborator

处理一下冲突哦

@huhuanming huhuanming enabled auto-merge (squash) January 30, 2026 06:48
@huhuanming huhuanming merged commit 059e0a8 into OneKeyHQ:x Jan 31, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants