Back to Skills

optimizing-performance

verified

Knowledge and patterns for identifying and resolving performance issues.

View on GitHub

Marketplace

ai-dev-marketplace

drewdresser/ai-dev-settings

Plugin

ai-dev

Repository

drewdresser/ai-dev-settings

skills/optimizing-performance/SKILL.md

Last Verified

January 22, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/drewdresser/ai-dev-settings/blob/main/skills/optimizing-performance/SKILL.md -a claude-code --skill optimizing-performance

Installation paths:

Claude
.claude/skills/optimizing-performance/
Powered by add-skill CLI

Instructions

# 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}"

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5095 chars