Systematically diagnose and fix performance bottlenecks in code. Use when the user reports slow operations, asks to speed up code, mentions performance issues, or when logs/profiling data shows unexpectedly long execution times.
Systematic approach to diagnosing and fixing performance bottlenecks.
Before optimizing anything:
Before any optimization, confirm tests exist that verify correctness:
# Run existing tests to establish baseline
pytest -q # or equivalent test command
If tests don't exist for the code being optimized:
Never optimize without data. Identify WHERE time is spent:
import time
start = time.monotonic()
# ... operation ...
elapsed_ms = (time.monotonic() - start) * 1000
print(f"Operation took {elapsed_ms:.1f}ms")
For database operations, count queries:
Key question: What is the algorithmic complexity?
See PATTERNS.md for common bottleneck patterns:
# After each optimization:
pytest -q # Verify tests pass
git add -A && git commit -m "perf: <description of optimization>"
Re-run the same measurement from Phase 2:
Stop optimizing when:
Parallelization is usually last resort - fix algorithmic issues first.
Is it slow?
├── No → Don't optimize
└── Yes → Do tests exist?
├── No → Write tests first (or ask user)
└── Yes → Profile to find bottleneck
└── Is it I/O bound? (DB, network, disk)
├── Yes → Batch operations, reduce round-trips
└── No → Is it O(n²) or worse?
├── Yes → Add index, change algorithm
└── No → Consider caching or parallelization
Use conventional commits for optimization changes:
perf: <short description> (<before> → <after>)
<Longer explanation of what was changed and why>
Examples:
perf: Batch DB reads (N queries → 2 queries)perf: Add amount index for O(1) lookupperf: Bulk insert transactions (N inserts → 1)Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer