AgentSkillsCN

refactoring-09-performance-profiling

在Python研究代码中进行性能剖析并做小幅度性能改进时使用。

SKILL.md
--- frontmatter
name: refactoring-09-performance-profiling
description: Use when profiling and making small performance improvements in Python research code.

Refactoring 09: Performance and Bottlenecks

Goal

Find hotspots with profiling and apply small, safe optimizations.

Sequence

  • Order: 09
  • Previous: refactoring-08-experiment-tracking
  • Next: refactoring-10-security-privacy

Workflow

  • Reproduce a slow path with a small, representative dataset.
    • Success: A repeatable slow case is identified.
  • Profile with a basic tool (cProfile, pyinstrument, or line_profiler).
    • Success: Hotspots are measured and recorded.
  • Apply minimal fixes (vectorization, caching, avoiding repeated IO).
    • Success: Targeted code changes are implemented.
  • Re-measure and record before/after metrics.
    • Success: Performance improvement is quantified.
  • Keep optimizations local and reversible.
    • Success: Changes are isolated and easy to revert.

Guardrails

  • Avoid algorithm changes unless requested.
  • Do not optimize without measurements.
  • Keep performance work separate from refactor-only changes.