ln-813-runtime-optimizer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Paths: File paths (
shared/
,
references/
,
../ln-*
) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.
路径: 文件路径(
shared/
references/
../ln-*
)相对于技能仓库根目录。如果在当前工作目录(CWD)中未找到,请定位到本SKILL.md所在目录,然后向上一级即为仓库根目录。

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

概述

AspectDetails
InputAudit findings from
docs/project/persistence_audit.md
(ln-653 section) OR target file
OutputOptimized code, verification report
Companionln-653-runtime-performance-auditor (finds issues) → ln-813 (fixes them)

维度详情
输入来自
docs/project/persistence_audit.md
(ln-653章节)的审计结果 或 目标文件
输出优化后的代码、验证报告
配套组件ln-653运行时性能审计工具(发现问题)→ ln-813(修复问题)

Workflow

工作流程

Phases: Pre-flight → Load Findings → Prioritize → Fix Loop → Report

阶段: 预检查 → 加载审计结果 → 优先级排序 → 修复循环 → 生成报告

Phase 0: Pre-flight Checks

阶段0:预检查

CheckRequiredAction if Missing
Audit findings OR target fileYesBlock optimization
Test infrastructureYesBlock (need tests for verification)
Linter availableNoSkip lint step in verification
Git clean stateYesBlock (need clean baseline for revert)
MANDATORY READ: Load
shared/references/ci_tool_detection.md
— use Test Frameworks + Linters sections.
检查项是否必填缺失时的操作
审计结果 或 目标文件阻止优化操作
测试基础设施阻止(验证需要测试支持)
代码检查工具可用跳过验证中的代码检查步骤
Git工作区干净阻止(需要干净的基准状态以便回滚)
必读内容: 加载
shared/references/ci_tool_detection.md
—— 参考测试框架 + 代码检查工具章节。

Worktree & Branch Isolation

工作区与分支隔离

MANDATORY READ: Load
shared/references/git_worktree_fallback.md
— use ln-813 row.

必读内容: 加载
shared/references/git_worktree_fallback.md
—— 参考ln-813相关内容。

Phase 1: Load Findings

阶段1:加载审计结果

From Audit Report

从审计报告加载

Read
docs/project/persistence_audit.md
, extract ln-653 findings:
Finding TypeOptimization
Blocking IO in async
asyncio.to_thread()
,
aiofiles
, async HTTP client
String concat in loop
StringBuilder
(.NET),
"".join()
(Python), template literals (JS)
Unnecessary allocationsPre-allocate collections, object pooling,
Span<T>
Sync sleep in async
asyncio.sleep()
,
Task.Delay()
,
setTimeout
Redundant serializationCache serialized form, avoid round-trip JSON in memory
读取
docs/project/persistence_audit.md
,提取ln-653的审计结果:
问题类型优化方案
异步代码中的阻塞式IO
asyncio.to_thread()
aiofiles
、异步HTTP客户端
循环中的字符串拼接
.NET
StringBuilder
、Python的
"".join()
、JS的模板字符串
不必要的内存分配预分配集合、对象池、
Span<T>
异步代码中的同步休眠
asyncio.sleep()
Task.Delay()
setTimeout
冗余序列化缓存序列化结果、避免内存中的JSON往返转换

From Target File

从目标文件加载

If no audit report: scan target file for runtime patterns matching the table above.

如果没有审计报告:扫描目标文件,查找与上表匹配的运行时模式。

Phase 2: Prioritize Fixes

阶段2:修复优先级排序

PriorityCriteria
1 (highest)Blocking IO in async context (blocks event loop)
2Sync sleep in async (starves thread pool)
3Allocations in hot loop (GC pressure)
4String concatenation patterns
5Other 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 report
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 report

Keep/Discard Decision

保留/丢弃决策

ConditionDecision
No tests cover affected file/functionSKIP finding — log as "uncovered, skipped"
Tests + lint passKEEP
Tests failDISCARD + log reason
Lint fail (new warnings)DISCARD + log reason
Lint unavailableKEEP (tests sufficient)

条件决策
没有测试覆盖受影响的文件/函数跳过该问题 —— 记录为“未覆盖,已跳过”
测试 + 代码检查均通过保留
测试失败丢弃 + 记录原因
代码检查失败(新增警告)丢弃 + 记录原因
无代码检查工具保留(测试已足够)

Phase 4: Report Results

阶段4:生成结果报告

Report Schema

报告结构

FieldDescription
sourceAudit report path or target file
findings_totalTotal findings from audit
fixes_appliedSuccessfully kept fixes
fixes_discardedFailed 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_serialization

yaml
选项:
  # 来源
  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_serialization

Error Handling

错误处理

ErrorCauseSolution
No audit findingsln-653 not run or no issuesReport "no findings to optimize"
Async rewrite complexDeep call chain affectedLog as manual step, skip
Framework-specific patternUnknown async frameworkQuery Context7/Ref for docs

错误原因解决方案
无审计结果ln-653未运行或未发现问题报告“无需要优化的问题”
异步重写复杂深层调用链受影响记录为手动步骤,跳过
框架特定模式未知的异步框架查询Context7/参考文档

References

参考资料

  • ../ln-653-runtime-performance-auditor/SKILL.md
    (companion: finds issues)
  • shared/references/ci_tool_detection.md
    (test + lint detection)

  • ../ln-653-runtime-performance-auditor/SKILL.md
    (配套组件:发现问题)→ ln-813(修复问题)
  • 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 ",