ln-813-runtime-optimizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePaths: File paths (,shared/,references/) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.../ln-*
路径: 文件路径(、shared/、references/)相对于技能仓库根目录。如果在当前工作目录(CWD)中未找到,请定位到本SKILL.md所在目录,然后向上一级即为仓库根目录。../ln-*
ln-813-runtime-optimizer
ln-813 运行时优化器
Type: L3 Worker
Category: 8XX Optimization
Parent: ln-810-performance-optimization-coordinator
Fixes runtime performance issues found by ln-653-runtime-performance-auditor. Each fix verified via tests + lint with keep/discard pattern.
类型: L3 工作组件
分类: 8XX 优化类
父组件: ln-810 性能优化协调器
修复由ln-653运行时性能审计工具发现的运行时性能问题。每个修复都会通过测试+代码检查,并采用保留/丢弃机制进行验证。
Overview
概述
| Aspect | Details |
|---|---|
| Input | Audit findings from |
| Output | Optimized code, verification report |
| Companion | ln-653-runtime-performance-auditor (finds issues) → ln-813 (fixes them) |
| 维度 | 详情 |
|---|---|
| 输入 | 来自 |
| 输出 | 优化后的代码、验证报告 |
| 配套组件 | ln-653运行时性能审计工具(发现问题)→ ln-813(修复问题) |
Workflow
工作流程
Phases: Pre-flight → Load Findings → Prioritize → Fix Loop → Report
阶段: 预检查 → 加载审计结果 → 优先级排序 → 修复循环 → 生成报告
Phase 0: Pre-flight Checks
阶段0:预检查
| Check | Required | Action if Missing |
|---|---|---|
| Audit findings OR target file | Yes | Block optimization |
| Test infrastructure | Yes | Block (need tests for verification) |
| Linter available | No | Skip lint step in verification |
| Git clean state | Yes | Block (need clean baseline for revert) |
MANDATORY READ: Load — use Test Frameworks + Linters sections.
shared/references/ci_tool_detection.md| 检查项 | 是否必填 | 缺失时的操作 |
|---|---|---|
| 审计结果 或 目标文件 | 是 | 阻止优化操作 |
| 测试基础设施 | 是 | 阻止(验证需要测试支持) |
| 代码检查工具可用 | 否 | 跳过验证中的代码检查步骤 |
| Git工作区干净 | 是 | 阻止(需要干净的基准状态以便回滚) |
必读内容: 加载 —— 参考测试框架 + 代码检查工具章节。
shared/references/ci_tool_detection.mdWorktree & Branch Isolation
工作区与分支隔离
MANDATORY READ: Load — use ln-813 row.
shared/references/git_worktree_fallback.md必读内容: 加载 —— 参考ln-813相关内容。
shared/references/git_worktree_fallback.mdPhase 1: Load Findings
阶段1:加载审计结果
From Audit Report
从审计报告加载
Read , extract ln-653 findings:
docs/project/persistence_audit.md| Finding Type | Optimization |
|---|---|
| Blocking IO in async | |
| String concat in loop | |
| Unnecessary allocations | Pre-allocate collections, object pooling, |
| Sync sleep in async | |
| Redundant serialization | Cache serialized form, avoid round-trip JSON in memory |
读取,提取ln-653的审计结果:
docs/project/persistence_audit.md| 问题类型 | 优化方案 |
|---|---|
| 异步代码中的阻塞式IO | |
| 循环中的字符串拼接 | |
| 不必要的内存分配 | 预分配集合、对象池、 |
| 异步代码中的同步休眠 | |
| 冗余序列化 | 缓存序列化结果、避免内存中的JSON往返转换 |
From Target File
从目标文件加载
If no audit report: scan target file for runtime patterns matching the table above.
如果没有审计报告:扫描目标文件,查找与上表匹配的运行时模式。
Phase 2: Prioritize Fixes
阶段2:修复优先级排序
| Priority | Criteria |
|---|---|
| 1 (highest) | Blocking IO in async context (blocks event loop) |
| 2 | Sync sleep in async (starves thread pool) |
| 3 | Allocations in hot loop (GC pressure) |
| 4 | String concatenation patterns |
| 5 | Other micro-optimizations |
| 优先级 | 判定标准 |
|---|---|
| 1(最高) | 异步上下文下的阻塞式IO(阻塞事件循环) |
| 2 | 异步代码中的同步休眠(耗尽线程池) |
| 3 | 热点循环中的内存分配(GC压力) |
| 4 | 字符串拼接模式 |
| 5 | 其他微优化 |
Phase 3: Fix Loop (Keep/Discard)
阶段3:修复循环(保留/丢弃机制)
Per-Fix Cycle
单个修复循环
FOR each finding (F1..FN):
1. APPLY: Edit code (surgical change)
2. VERIFY: Run tests
IF tests FAIL → DISCARD (revert) → next finding
3. VERIFY: Run lint (if available)
IF lint FAIL → DISCARD (revert) → next finding
4. BOTH PASS → KEEP
5. LOG: Record fix for reportFOR each finding (F1..FN):
1. APPLY: Edit code (surgical change)
2. VERIFY: Run tests
IF tests FAIL → DISCARD (revert) → next finding
3. VERIFY: Run lint (if available)
IF lint FAIL → DISCARD (revert) → next finding
4. BOTH PASS → KEEP
5. LOG: Record fix for reportKeep/Discard Decision
保留/丢弃决策
| Condition | Decision |
|---|---|
| No tests cover affected file/function | SKIP finding — log as "uncovered, skipped" |
| Tests + lint pass | KEEP |
| Tests fail | DISCARD + log reason |
| Lint fail (new warnings) | DISCARD + log reason |
| Lint unavailable | KEEP (tests sufficient) |
| 条件 | 决策 |
|---|---|
| 没有测试覆盖受影响的文件/函数 | 跳过该问题 —— 记录为“未覆盖,已跳过” |
| 测试 + 代码检查均通过 | 保留 |
| 测试失败 | 丢弃 + 记录原因 |
| 代码检查失败(新增警告) | 丢弃 + 记录原因 |
| 无代码检查工具 | 保留(测试已足够) |
Phase 4: Report Results
阶段4:生成结果报告
Report Schema
报告结构
| Field | Description |
|---|---|
| source | Audit report path or target file |
| findings_total | Total findings from audit |
| fixes_applied | Successfully kept fixes |
| fixes_discarded | Failed fixes with reasons |
| fix_details[] | Per-fix: finding type, file, before/after description |
| 字段 | 描述 |
|---|---|
| source | 审计报告路径或目标文件 |
| findings_total | 审计发现的问题总数 |
| fixes_applied | 成功保留的修复数量 |
| fixes_discarded | 失败的修复及原因 |
| fix_details[] | 单个修复详情:问题类型、文件、修复前后描述 |
Configuration
配置
yaml
Options:
# Source
audit_report: "docs/project/persistence_audit.md"
target_file: ""
# Verification
run_tests: true
run_lint: true
# Scope
fix_types:
- blocking_io
- sync_sleep
- unnecessary_alloc
- string_concat
- redundant_serializationyaml
选项:
# 来源
audit_report: "docs/project/persistence_audit.md"
target_file: ""
# 验证
run_tests: true
run_lint: true
# 范围
fix_types:
- blocking_io
- sync_sleep
- unnecessary_alloc
- string_concat
- redundant_serializationError Handling
错误处理
| Error | Cause | Solution |
|---|---|---|
| No audit findings | ln-653 not run or no issues | Report "no findings to optimize" |
| Async rewrite complex | Deep call chain affected | Log as manual step, skip |
| Framework-specific pattern | Unknown async framework | Query Context7/Ref for docs |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 无审计结果 | ln-653未运行或未发现问题 | 报告“无需要优化的问题” |
| 异步重写复杂 | 深层调用链受影响 | 记录为手动步骤,跳过 |
| 框架特定模式 | 未知的异步框架 | 查询Context7/参考文档 |
References
参考资料
- (companion: finds issues)
../ln-653-runtime-performance-auditor/SKILL.md - (test + lint detection)
shared/references/ci_tool_detection.md
- (配套组件:发现问题)→ ln-813(修复问题)
../ln-653-runtime-performance-auditor/SKILL.md - (测试+代码检查工具检测)
shared/references/ci_tool_detection.md
Definition of Done
完成标准
- Findings loaded from audit report or target file scan
- Fixes prioritized (blocking IO first, then sync sleep, allocations, string concat)
- Each fix applied with keep/discard: tests + lint pass → keep, either fails → discard
- Report returned with findings total, fixes applied, fixes discarded
Version: 1.0.0
Last Updated: 2026-03-08
- 已从审计报告或目标文件扫描加载问题
- 已对修复任务进行优先级排序(先处理阻塞式IO,再处理同步休眠、内存分配、字符串拼接)
- 每个修复均通过保留/丢弃机制验证:测试+代码检查通过则保留,任一失败则丢弃
- 已生成包含问题总数、已应用修复数、已丢弃修复数的报告
版本: 1.0.0
最后更新时间: 2026-03-08
",