Repository navigation
perf(cli): load performance diagnosis on demand - #7678
Conversation
Signed-off-by: lusendong.6789 <lusendong.6789@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: actor_kind=model_agent; model=gpt-6.1-sol; provider=OpenAI; reasoning_effort=max; declaration_source=runtime_reported.
动机 / Motivation
APPROVE:未发现阻断问题,加载成本下降有独立对照。
使用本地性能诊断命令的开发者,原本连读取帮助都要等待完整 CLI 加载。
过去 help、plan 和 inspect 都进入完整命令树;现在已知有效参数走现有按需 parser,错误参数仍回到原完整 parser 生成诊断。
独立基线对照验证输出逐字节相同,并在新进程中测得 help、plan、inspect 的加载耗时下降。
本次不运行用户待诊断命令、不上传 profile、不增加权限,也不声称完成最小发行包或真实长程任务收益验收。
R0 的更广加载指标与 D6 预算决策、最小/标准组合、安装和真实 Turn 资格仍需由原路线继续验证。
改动思路 / Approach
命令语法和 handler 仍各有一个 owner,完整与按需入口复用同一 dispatch;删除冗余分支即可取得已测收益。
当前 PR 只交付既有性能诊断命令的按需加载与兼容验证;保持原 TypeScript 诊断、请求范围和错误恢复边界。
帮助在 parse 阶段结束,因而不会为了显示参数导入 Effect;真实 plan/inspect 仍走现有 TypeScript owner。完整 CLI 与按需入口共用同一 handler,错误参数继续由原完整 parser 报告,避免为“快”而丢掉原来的恢复信息。这是可单独回退的加载缝隙,不需要先完成目录或发行包拆分。
具体改动 / Changes
评审完整 head:9864e29dd85a9be21b1192950ddd4cc813d907d7;不可变基线:8caaf678e52019453ca3e5a2adf363c954ae2642。规范依据 loopx/capabilities/performance_diagnosis/README.md @ 8caaf678e52019453ca3e5a2adf363c954ae2642:Placement and ownership、Run and read back、Disable by not invoking 三条均 implemented;Python 仍只做文件/CLI transport,TypeScript 保持诊断语义,plan 不执行目标,未调用时不启动后台采集。它符合既有 R0 路线,但这份评审不宣告 D6、全量 V10、R1–R4 或 split-package 资格完成。
关键代码讲解
- _build_selected_parser 将命令交给已有 registrar;global/local format、registry optionality 与完整选项名规则继续复用 canonical grammar。
- _dispatch_common_command 让完整及按需路径进入同一个 handler;
cli.py原有重复 dispatch 分支被删除。 - handle_performance_diagnosis_command 在实际 dispatch 后才加载 Effect;16 MiB 文件限制、大 snapshot transport、输出及异常处理没有重写。
对主干的风险 / Risks
最值得怀疑的是新 full/selected 路径彼此相同,却共同偏离旧 CLI。因此我另以不可变基线直接运行相同公开入口:3 个正向工作负载输出逐字节相同,11 个无效/缺失输入案例的完整诊断和退出状态也一致。3 个帮助隔离审计在基线都因加载完整 CLI 失败,在 head 全通过;同时禁止了 Effect、进程和网络作用。
PASS:176 项 Python 测试、12 项真实 TypeScript 测试,包括真实 Node capture/readback、大 profile、missing Node、JSON/Markdown 与 format 优先级。plan 没有创建目标 capture 目录,显式缺省 registry 也没有被创建。
独立测量环境为 macOS arm64、Python 3.14.8、Node 24.21.0;每项 10 对交替的新 Python 进程,文件缓存预热,plan/inspect 的实际 Node 服务先预热。下表为 median / nearest-rank p95,单位 ms;10 样本的该 p95 为最大值。
| 工作负载 | 基线 | head |
|---|---|---|
| help | 486.4 / 644.9 | 46.3 / 51.3 |
| plan | 531.4 / 567.5 | 91.8 / 101.8 |
| inspect | 535.9 / 629.4 | 100.5 / 116.8 |
宿主负载未完全控制,绝对值不等同作者的另一环境;这里没有把 CLI 速度换算成模型 token、费用或任务吞吐收益。标准 native premerge 全通过,精确范围 CQR 有效;Ruff 和仓库配置的 17-file mypy 均通过。 没有查询、轮询或等待远端 CI。
我的整体评价 / Verdict
这是有用且可回退的 justified_increment:长程语义 preserved,当前 CLI 使用体验 improved,用户执行同一命令不需新增配置或确认。相邻简化已体现在删除重复 handler 和延后 import;不应为这一命令另建执行框架。语义分类为 reuse_existing,现有 opt-in 能力不会因可见、导入或读取帮助而获得执行权限。
本次只调整 CLI 加载和测试;既有设置页面与 profile worker 没有改动,不需要页面截图。
未验证发布后的安装、多平台延迟、minimal/standard 组合或完整任务成本;本机 CLI 测量不代表这些资格。
English verdict: APPROVE
performance-diagnosiscurrently loads the complete CLI even to print its help. Route it through the existing selected parser and common dispatcher, and defer the capability's Effect runtime import until execution. Both routes reuse the same registrar, handler and TypeScript diagnosis owners.This is the bounded R0 implementation from #7672. It preserves registry optionality, global/local format precedence, planning and profile inspection, and canonical argument diagnostics. Invalid argument paths still use the full-parser fallback. The adjacent simplification removes the redundant full-CLI handler branch; no additional abstraction is needed for this command.
Validation:
8caaf678e52019453ca3e5a2adf363c954ae2642: 26 parser/dispatch/error cases passed. All three optional-import isolation cases failed on the old path by detectingloopx.cli, establishing regression sensitivity.python -m pytest tests/capabilities/test_performance_diagnosis.py tests/capabilities/test_performance_diagnosis_cli.py tests/test_cli_entrypoint.py tests/control_plane/test_source_cli_entrypoint.py -q: 176 passed, including real Node capture/inspection, large profiles, missing Node and full/selected JSON/Markdown equality.node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/performance_diagnosis.test.ts: 12 passed.npm ci --ignore-scripts, that smoke passed on retry. All selected checks are now covered; the initial aggregate is retained as a failed setup attempt, not reported as green.Review entry does not grant merge authority. Required remote checks and maintainer review remain pending.
Performance evidence (macOS arm64; usage collection disabled):
These are 10 alternating fresh-process pairs per workload, with warm filesystem caches and an already running real shared Node service for plan/inspect. Outputs were byte-identical. A separate 30-run before/after help sample measured 1,239.39 → 38.00 ms (p95 1,397.92 → 44.55 ms). Absolute latency varies across runs; the paired comparison is the same-run control. These are CLI costs, not benchmark-task throughput claims.
The help import trace dropped from 1,145 to 12 LoopX modules, file opens from 1,275 to 33, and peak RSS from 83.4 to 22.2 MB. The trace observed zero process starts and zero network connections with usage collection disabled. Raw timing/profile artifacts remain outside the repository.