Knowledge and patterns for identifying and resolving performance issues.
View on GitHubdrewdresser/ai-dev-settings
ai-dev
skills/optimizing-performance/SKILL.md
January 22, 2026
Select agents to install to:
npx add-skill https://github.com/drewdresser/ai-dev-settings/blob/main/skills/optimizing-performance/SKILL.md -a claude-code --skill optimizing-performanceInstallation paths:
.claude/skills/optimizing-performance/# Optimizing Performance Skill
This skill provides patterns and techniques for performance optimization.
## Performance Analysis Process
### 1. Measure First
```bash
# Python profiling
python -m cProfile -s cumtime script.py
# Memory profiling
python -m memory_profiler script.py
# Node.js profiling
node --prof app.js
node --prof-process isolate-*.log > processed.txt
```
### 2. Identify Bottlenecks
- CPU-bound: Computation heavy
- I/O-bound: Waiting for disk/network
- Memory-bound: High memory usage
- Concurrency: Lock contention
### 3. Optimize Systematically
- Focus on hotspots (80/20 rule)
- One change at a time
- Measure after each change
- Document trade-offs
## Common Optimizations
### Database
#### N+1 Query Problem
```python
# Bad: N+1 queries
users = User.query.all()
for user in users:
print(user.orders) # Query per user!
# Good: Eager loading
users = User.query.options(joinedload(User.orders)).all()
for user in users:
print(user.orders) # Already loaded
```
#### Indexing
```sql
-- Identify slow queries
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'test@example.com';
-- Add index
CREATE INDEX idx_users_email ON users(email);
-- Composite index for common queries
CREATE INDEX idx_orders_user_status ON orders(user_id, status);
```
#### Query Optimization
```sql
-- Bad: SELECT *
SELECT * FROM users WHERE status = 'active';
-- Good: Select needed columns
SELECT id, name, email FROM users WHERE status = 'active';
-- Bad: LIKE with leading wildcard
SELECT * FROM users WHERE name LIKE '%john%';
-- Better: Full-text search or specific patterns
SELECT * FROM users WHERE name LIKE 'john%';
```
### Caching
#### Application-Level Cache
```python
from functools import lru_cache
@lru_cache(maxsize=128)
def expensive_computation(x, y):
return complex_calculation(x, y)
```
#### Distributed Cache (Redis)
```python
import redis
cache = redis.Redis()
def get_user(user_id):
# Try cache first
cached = cache.get(f"user:{user_id}"