The Three Rules of Optimization
You'll learn the three famous rules that keep performance work productive and prevent wasted effort.
The Golden Rules
These three rules, popularized by Michael A. Jackson, form the foundation of smart performance engineering:
Rule 1: Don't do it.
Many performance problems disappear when you reconsider whether something needs to happen at all. Can you avoid the work entirely? Can you defer it until it's actually needed? Can you eliminate a feature that adds little value but costs a lot?
Rule 2: Don't do it yet.
Don't optimize code that isn't causing problems. Write clear, maintainable code first. Only optimize when measurements prove there's a real performance issue. As you learned from "Premature Optimization Is the Root of All Evil," optimizing too early wastes time and makes code harder to maintain.
Rule 3: Profile before optimizing.
When you do need to optimize, measure first. Use the performance measurement tools you've learned—console.time, performance.now, DevTools profiling, Performance Observers—to find the actual bottleneck. Your intuition about what's slow is often wrong.
Why This Order Matters
Think of it like home repair: before tearing apart your walls, first confirm the problem exists (measure), then check if you can avoid the problem entirely (don't do it), and only if necessary, schedule it for the right time (don't do it yet).
These rules work together with the "80/20 Rule in Performance" you learned—most performance impact comes from a small number of bottlenecks, so profiling reveals where to focus effort.
Key Takeaway: The three rules of optimization form a decision hierarchy: eliminate unnecessary work first, defer optimization until it's needed second, and always measure before optimizing third.