Perf Doctor
Overview
Give the agent a deterministic, repo-wide performance audit. Instead of only guessing, run scripts/scan_perf.py to surface concrete hot spots with file:line, severity, and a fix suggestion, then prioritize by severity (High -> Medium -> Low).
When to Use
- The user says "性能审计", "perf-doctor", "检查性能", "为什么慢", "performance audit", "帮我看性能".
- After a feature lands and before declaring it done, as a perf gate.
Procedures
- Scan: run
python scripts/scan_perf.py <project_dir>(or a single file). The scanner is stdlib-only and needs no install. - Triage: read the report; start with
Highfindings (N+1, sync-in-loop), thenMedium, thenLow. - Fix + verify: apply the suggested fix, then re-run the scanner to confirm the finding is gone. Remind the user: measure before/after (a benchmark or timing), don't optimize blind.
- Report: summarize counts by severity and the top 3 fixes.
Bundled Resources
scripts/scan_perf.py— heuristic scanner for Python/JS/TS/Java/Go and more. Outputs a table or--json; exits non-zero when findings exist (CI-friendly).references/perf-rules.md— the full rule catalog with fix patterns.
Guardrails
- Heuristics, not a profiler: findings are candidates, notproof. Confirm with a real benchmark before claiming a win.
- Avoid shotgun "optimizations": fix the High items first; low-severity items may not be worth the churn.
- Do not rewrite working code just to satisfy the scanner; only change when there is a real measured gain.