AgentSkillsCN

rescue-optimization

为缺乏基准测试的优化工作提供补救方案。生成缺失的证据,验证各项主张。在挽救过程中发现的 Bug 同样弥足珍贵——此时可调用 /validate-correctness 来进一步验证这些 Bug。

SKILL.md
--- frontmatter
name: rescue-optimization
description: Salvages optimization work lacking benchmarks. Generates missing evidence, validates claims. Bugs discovered during rescue are valuable - invoke /validate-correctness.

Optimization Rescue

Salvage optimization work done without proper benchmarks. Generate evidence, validate claims, and discover bugs hiding in "optimizations."

Valuable Outcomes

OutcomeValueAction
Change validatedReal improvement provenKEEP, include in rescued branch
Change invalidatedNo improvementDISCARD, record lesson
Bug discoveredCorrectness issue foundInvoke /validate-correctness

Bugs found during rescue are SUCCESS, not failure.


Phase 0: Pre-flight

Run /preflight first.


Phase 1: Audit

bash
git diff --name-only origin/main...HEAD | grep '\.go$'

For each change, categorize:

  • Preallocation
  • Pooling
  • Buffer reuse
  • Data structure change
  • Potential bug (suspicious patterns)

Phase 2: Triage

Hot Path?Decision
Yes (top 10%)INVESTIGATE
Warm (10-25%)SKEPTICAL
ColdLIKELY DISCARD
Looks buggyINVESTIGATE for correctness

Bug Warning Signs

  • make([]T, n) followed by append
  • Missing nil checks
  • Changed return semantics
  • Slice aliasing

Phase 3: Generate Evidence

Create Benchmarks

go
func BenchmarkFunction(b *testing.B) {
    data := createTestData()
    b.ReportAllocs()
    b.ResetTimer()
    for i := 0; i < b.N; i++ {
        _ = Function(data)
    }
}

Run Comparison

bash
benchstat /tmp/baseline.txt /tmp/optimized.txt

Phase 4: Validate

benchstat ResultDecision
>=5% improvement, p<0.05KEEP
No significant changeDISCARD
Tests failPossible BUG → /validate-correctness
Behavior differsPossible BUG → /validate-correctness

Phase 5: Handle Bug Discovery

If rescue uncovers a bug instead of an optimization:

code
/validate-correctness

After validation:

  1. Record bug in validations.yaml (via validate-correctness)
  2. Record rescue as BUG_FOUND in rescues.yaml
  3. The bug fix becomes part of rescued branch (with tests!)

Phase 6: Reconstruct

bash
git checkout main
git checkout -b mem-opt/<name>-rescued

Apply only:

  • KEEP changes (validated optimizations)
  • BUG_FOUND changes (with tests from /validate-correctness)

Discard everything else.


Phase 7: Record

yaml
# Append to rescues.yaml
  - branch: mem-opt/original
    date: 2026-01-06
    audited: 12
    kept: 3
    discarded: 7
    bugs_found: 2
    rescued_as: mem-opt/original-rescued
    lesson: "<pattern>"

Usage

code
/rescue-optimization