SOLID & Design Patterns Interview Question #129
What is Premature Optimization?
Anti-Patterns, Refactoring, DI Lifetimes & Senior Design Scenarios Senior Advanced
Quick Interview Answer
Premature Optimization means increasing complexity to improve performance before evidence shows that the targeted area is a meaningful bottleneck. It can make code harder to understand while producing little measurable benefit.
Detailed Explanation
Premature Optimization means increasing complexity to improve performance before evidence shows that the targeted area is a meaningful bottleneck. It can make code harder to understand while producing little measurable benefit.
Establish performance requirements, measure representative workloads, identify the actual bottleneck, optimize it, and measure again. This does not mean ignoring obvious algorithmic or resource problems during design.
Code Example
// Prefer measurement:
var sw = Stopwatch.StartNew();
await ExecuteScenarioAsync();
Console.WriteLine(sw.Elapsed);
// Optimize the measured bottleneck,
// not an assumed one.