Community编程与开发github.com

OpenClaw 测试性能优化

基准测试、诊断并优化 OpenClaw 测试及插件套件运行时性能,包括导入热点、CPU/RSS、堆增长及慢覆盖路径。

OpenClaw 测试性能优化 是什么?

该技能旨在系统性地对 OpenClaw 项目的测试性能进行基准测试、诊断与优化。它指导用户通过阅读相关 `AGENTS.md` 文件来定位潜在热点,并在修改代码前建立性能基线。技能涵盖了全套件排名、插件批处理、作用域热点分析等多种场景的具体命令和指标收集方法,如 wall time、Vitest duration、max RSS 等。它强调依据证据而非猜测进行优化,并详细描述了从根因分析、修复实施到重新基准测试与报告更新的完整工作流程。该技能支持 `pnpm test`、插件套件 (plugin-suite) 和插件检查器 (plugin-inspector) 等主要测试场景,并区分了高回报/高杠杆与低风险/高风险的不同优化攻击方向。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clawdbot/clawdbot/tree/main/.agents/skills/openclaw-test-performance

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

OpenClaw 测试性能

一切以证据为准。目标是实实在在提升 pnpm test、插件套件 (plugin-suite) 和 插件检查器 (plugin-inspector) 的速度/降低 RSS,同时保持代码覆盖率不变,而非凭猜测调优运行器。

工作流程

  1. 编辑前先阅读相关的本地 AGENTS.md 文件:
    • src/agents/AGENTS.md 针对代理/导入热点。
    • src/channels/AGENTS.md 和 src/plugins/AGENTS.md 针对插件/通道的懒加载。
    • src/gateway/AGENTS.md 针对服务器生命周期测试。
    • test/helpers/AGENTS.md 和 src/channels/plugins/contracts/test-helpers/AGENTS.md 针对共享合约辅助函数。
    • src/infra/outbound/AGENTS.md 针对出站/媒体/动作测试。
  2. 在修改代码前建立基准:
    • 推荐使用 pnpm test:perf:groups --full-suite --allow-failures --output <file> 进行全套件排名。
    • 对于捆绑插件的广度测试,在跳转到全扩展扫描之前,先运行最小的相关 pnpm test:extensions:batch <plugin[,plugin...]> 或插件检查器命令。
    • 对于作用域热点,使用: /usr/bin/time -l pnpm test <file-or-files> --maxWorkers=1 --reporter=verbose
    • 如果怀疑导入开销大,可添加以下环境变量: OPENCLAW_VITEST_IMPORT_DURATIONS=1 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1。
  3. 将 wall time/运行器噪声与实际文件成本分开:
    • 比较 Vitest 持续时间、测试主体计时、导入分解、wall time 和最大 RSS。
    • 当分组/全套件的数据看起来过时或噪声大时,重新单独运行文件。
    • 如果全套件分组运行报告了一个通道失败,但 JSON 显示测试通过,则将其视为测试框架/噪声,并直接验证可疑文件。
  4. 根据回报和风险选择下一个攻击方向:
    • 高回报:某个文件/测试占用数秒或大量 RSS,且有明确的根因。
    • 高杠杆:某个插件或 SDK barrel 导致每次插件检查器或扩展批处理运行都加载了宽泛的运行时。
    • 较低风险:静态描述符、目标解析、路由、认证绕过、安装提示、注册表 fixture 或测试服务器生命周期。
    • 较高风险:真实内存/运行时行为、实时提供者、协议合约或大规模生产重构。
  5. 修复根因,而非症状:
    • 将静态元数据/解析移至窄范围的辅助函数或轻量级工件中,以便全运行时和快速路径复用。
    • 倾向于使用依赖注入、仅加载已加载插件的查找、显式的 fixture 和纯辅助函数,而非宽泛的 mock。
    • 当握手无关紧要时,复用套件级别的服务器/客户端。
    • 除非测试本身证明需要调度,否则保持调度器/后台循环关闭。
    • 在插件路径中,将静态元数据移至 manifest/轻量级工件中,并将运行时插件加载保持在显式的执行边界之后。
  6. 保持覆盖率形状:
    • 不要删除一个缓慢的集成证明测试,除非确切的生产组合已被提取到一个命名的辅助函数中并经过了测试。
    • 当跨组件连接很重要时,保留一个廉价的集成冒烟测试。
    • 明确说明移除了哪些附带的覆盖率(如果有的话)。
  7. 在更改后,使用相同的命令重新进行基准测试,并计算秒数和百分比增益。
  8. 当被要求或当前线程正在跟踪时,更新运行报告。 包括 before/after 命令、工件、覆盖率说明、验证和下一步攻击顺序。
  9. 暂存预期的路径,使用标准 Git 提交,并在用户要求提交/推送时推送。仅暂存为此攻击触碰的文件。

插件套件工作流程

对于捆绑插件、插件检查器、SDK barrels、包边界测试或扩展套件,在选选择基准或证明之前,请完整阅读 插件套件工作流程。它涵盖了套件广度、宿主选择和包工件的升级路径。

指标收集

在修改前后至少收集一个稳定的指标。优先使用同一台机器和相同的命令。对于 Testbox 比较,尽可能使用相同的 tbx_... ID。

指标用途推荐来源
wall time用户可见的套件成本/usr/bin/time -l、测试包装器持续时间、Testbox 运行时间
Vitest 持续时间测试主体/导入成本每个文件/分片的 Vitest 输出
导入持续时间宽泛的 barrel/运行时加载OPENCLAW_VITEST_IMPORT_DURATIONS=1
最大 RSS内存压力和 OOM 风险/usr/bin/time -l、pnpm test:extensions:memory、包装器内存摘要
CPU/user/sysCPU 密集型与等待密集型分离本地使用 /usr/bin/time -l,当本地 CPU 噪声大时使用 Testbox 任务计时
堆证据真实泄漏与保留的模块图openclaw-test-heap-leaks 工作流程

带 CPU/RSS 的本地作用域命令:

timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose

插件导入内存分析:

pnpm build
pnpm test:extensions:memory -- --top 20 --json .artifacts/test-perf/extensions-memory.json

指定插件的导入内存:

pnpm test:extensions:memory -- --extension discord --extension telegram --skip-combined

堆/RSS 升级:

pnpm test:perf:groups \
  --config test/vitest/vitest.unit-fast.config.ts \
  --allow-failures \
  --output .artifacts/test-perf/unit-fast-memory.json
pnpm test:perf:profile:runner -- \
  --output-dir .artifacts/test-perf/vitest-runner-profile -- <file>

当 RSS 在时间间隔内持续增长、工作进程 OOM,或可疑命令存在应用对象保留时,使用 openclaw-test-heap-leaks。在快照或保留器支持之前,不要将 RSS 增长称为泄漏。

常见根因

  • 为获取静态数据而加载了完整的捆绑通道/插件运行时。
  • 本可以使用已加载的 fixture 或纯解析器时,却回退使用了 getChannelPlugin()。
  • 将宽泛的 api.ts、runtime-api.ts、test-api.ts 或插件 SDK barrels 拉入到热点测试中。
  • SDK 根别或包 barrels 将聚焦的子路径拉回宽泛的插件图。
  • 仅为了渲染元数据、报告或 CI 策略评分,插件检查器就加载了运行时代码。
  • 捆绑插件捕获复用了真实的配置/主目录状态,而非合成的、脱敏的、隔离的状态。
  • 使用围绕宽泛模块的 importActual() 进行部分真实的 mock。
  • 在每测试循环中使用 vi.resetModules() 加上新的导入。
  • 在 beforeAll 中播种测试插件注册表,却在 afterEach 中重置运行时状态。
  • 当状态重置就足够时,却进行每测试的网关/服务器/客户端启动。
  • 运行时/默认模型/认证选择被闲置的快照或 fixture 付出成本。
  • 在检查参数是否包含插件拥有的字段之前,就触发了插件拥有的媒体/动作发现。
  • 并行的 Vitest 运行共享了 node_modules/.experimental-vitest-cache,而没有使用不同的 OPENCLAW_VITEST_FS_MODULE_CACHE_PATH 值。

基准命令

作用域文件:

timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose

带导入分解的作用域文件:

timeout 240 /usr/bin/time -l env \
  OPENCLAW_VITEST_IMPORT_DURATIONS=1 \
  OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1 \
  pnpm test <file> --maxWorkers=1 --reporter=verbose

分组套件:

pnpm test:perf:groups --full-suite --allow-failures \
  --output .artifacts/test-perf/<name>.json

扩展批处理:

pnpm test:extensions:batch <plugin[,plugin...]> -- --reporter=verbose

所有扩展测试:

pnpm test:extensions

包边界插件检查:

pnpm run test:extensions:package-boundary:canary
pnpm run test:extensions:package-boundary:compile

复用现有的 Vitest JSON 报告:

pnpm test:perf:groups --report <vitest-json> \
  --output .artifacts/test-perf/<name>.json

验证

  • 始终运行能够证明变更的针对性测试范围。
  • 遵循 OpenClaw 测试 了解聚焦测试、 所需构建、证明路由和发布时机。
  • 对于仅测试的变更,通过该所有者支持的命令运行被编辑的精确测试。
  • 对于插件 SDK/barrel/运行时变更,当公共 API 表面可能漂移时,使用 pnpm plugin-sdk:api:diff -- --base <base-sha> --head <head-sha> 比较精确的提交。对于 PR 本地的证明,使用分支合并基作为 <base-sha>,使用被测试的确切头提交作为 <head-sha>。
  • 对于插件套件的性能修复,至少验证一个具有代表性的插件批处理以及更改后的门控;如果错误仅存在于打包后的工件中,则使用包验收测试。
  • 对于缺失或过期的依赖,遵循源代码依赖和当前工作树所有者的说明。使用合格的证明路由。
  • 使用报告格式:
| 指标          | 优化前 | 优化后 |          收益 |
| ------------- | -----: | -----: | ------------: |
| 文件 wall 时间 |   `Xs` |   `Ys` |  `-Zs` (`P%`) |
| 最大 RSS      |  `XMB` |  `YMB` | `-ZMB` (`P%`) |
| CPU 用户/系统  | `X/Ys` | `A/Bs` |       解释     |

交接

保持最终信息简洁:

  • 根因。
  • 套件/插件范围。
  • 更改的文件。
  • 优化前后 wall、Vitest/导入、CPU 和 RSS 数据(如果有)。
  • 如果涉及内存,泄漏分类:真实泄漏、保留的模块图或不确定。
  • 覆盖率保持情况。
  • 验证命令。
  • 用于远程证明的 Testbox ID 或工作流 URL。
  • 提交哈希和推送状态。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

acp-router

Route plain-language requests for Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Grok Build, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.

add-model-provider

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

agent-transcript

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

apple-notes

Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.

apple-reminders

List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.

auto-qa

Run OpenClaw-wide autonomous QA and live/stress campaigns across independent subsystem lanes, with verified fixes and a resumable evidence report.

autoreview

Structured code review through the shared OpenClaw agent-skills installation.

bear-notes

Create, search, and manage Bear notes via grizzly CLI.

blacksmith-testbox

Run Blacksmith Testbox for CI-parity checks, secrets, hosted services, migrations, or builds local cannot reproduce.

block-kit

Use proactively for structured or interactive Slack replies, and when asked to author or validate native Slack Block Kit JSON.

blogwatcher

Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.

blucli

BluOS CLI (blu) for discovery, playback, grouping, and volume.

bluebubbles

Send and manage iMessages via BlueBubbles, including attachments, tapbacks, edits, replies, and groups.

browser-automation

Use when controlling web pages with the OpenClaw browser tool, especially multi-step flows, login checks, tab management, or recovery from stale refs/timeouts.

camsnap

Capture frames or clips from RTSP/ONVIF cameras and local webcams, including USB pan/tilt/zoom control.

canvas

Present HTML on connected OpenClaw node canvases, navigate/eval/snapshot, and debug canvas host URLs.

channel-message-flows

Use when running QA Lab channel message flow evidence.

clawdtributor

Clawtributor PRs here, last week or another window: discover conversation refs, recheck GitHub, rank by impact.

clawhub

Search ClawHub for plugins by default, or skills and agent Templates when requested; add Templates; install, verify, update, uninstall, publish, or sync skills.

相关技能