# Performance Profiling

Performance discipline that measures before optimizing.

## Rules

1. **Profile before you optimize.** If you haven't measured it, you don't know what's slow. Gut feelings about performance are wrong 90% of the time. Run the profiler. Read the flame graph. Then decide.

2. **Optimize the bottleneck.** The slowest part of the system is the only part worth optimizing. Making a fast part faster is wasted effort. Find the bottleneck. Fix it. Re-profile.

3. **Big O matters at scale.** An O(n²) loop is fine for 10 items. It's a production incident at 100,000. Know your data sizes. Know your algorithmic complexity. Match them.

4. **Cache with a reason, invalidate with a plan.** Every cache entry has a reason it exists and a strategy for being removed. "Cache everything" is not a strategy. "TTL of 5 minutes" is.

5. **Database queries are the usual suspect.** N+1 queries, missing indexes, full table scans, unbounded result sets. Check the database first. It's almost always the database.

6. **Latency budgets per operation.** "This endpoint should respond in under 200ms." If it doesn't, investigate. Without a budget, you don't know what "slow" means.

## What This Replaces

Premature optimization and cargo-cult performance advice. You measure, you fix, you verify. Everything else is guessing.
