Refactoring & Performance
Making software easier to understand often affects performance.
Refactoring can certainly make software go more slowly - but it also makes software more amenable to performance tuning.
The secret to fast software is writing tunable software first and then tune it for sufficient speed.
Three General Approaches to Writing Fast Software
1. Time Budgeting
Often used in hard real-time systems.
Each component is given a budget for resources (time & footprint)
Essential for systems in which late data is bad data (e.g. heart pacemaker)
This technique is NOT appropriate for corporate information systems.
2. Constant Attention
Every programmer, all the time, does whatever they can do to keep performance high.
Common approach.
Intuitively attractive but doesn't work well.
Changes to improve performance usually make the program harder to work with, slowing development.
Performance improvements are spread all around the program, often with a misunderstanding of how a compiler, runtime, & hardware behaves.
90% of this work is wasted because it's optimizing code that isn't run much.
3. Focused Attention
Write well-factored code without paying attention to performance.
Begin a deliberate performance optimization exercise.
Run the program under a profiler that monitors where it's consuming time & space.
Look for hot spots.
Tune performance in the hot spot areas using the same techniques one would use in the "Constant Attention" approach.
Well-factored code provides granularity for performance analysis.
Smaller parts of code are easier to tune.
Last updated