From "Refactoring"
🎧 Listen to Summary
Free 10-min PreviewRefactoring for Performance and Step Management
Key Insight
A common concern during refactoring is its potential impact on performance, especially when steps involve repeating loops or making multiple function calls for previously computed values. However, for most refactorings, these changes have a negligible effect on overall performance. Developers, even experienced ones, often misjudge actual performance impacts, as modern compilers and caching techniques optimize code in unexpected ways.
The general advice is to prioritize clarity and structure during refactoring and to largely ignore performance concerns in the initial stages. If a refactoring *does* introduce a significant performance slowdown, the recommended approach is to complete the refactoring first. After the code is well-factored and clear, performance tuning can be addressed, which is considerably easier to do on a structured codebase, often leading to more effective optimizations that result in both clearer and faster code.
The rhythm of refactoring is characterized by taking extremely small, incremental steps, each followed immediately by compiling, testing, and committing the change to version control. This approach ensures the code remains in a working, tested state at all times. If an error occurs, reverting to the last good commit and redoing the change in even smaller steps simplifies debugging and accelerates the process, especially with difficult code, proving that moving quickly means taking tiny steps.
📚 Continue Your Learning Journey — No Payment Required
Access the complete Refactoring summary with audio narration, key takeaways, and actionable insights from Martin Fowler, Kent Beck.