👨‍💻
Software Engineering
Refactoring: Improving the Design of Existing Code
Refactoring: Improving the Design of Existing Code
  • Overview
  • Chapter 2
    • Defining Refactoring
    • Why Should We Refactor?
    • When Should We Refactor?
    • Problems with Refactoring
    • Refactoring, Architecture, and Yagni
    • Refactoring & the Wider Software Development Process
    • Refactoring & Performance
    • Going Further
  • Chapter 3
    • Bad Smells in Code
    • Smell: Mysterious Name
    • Smell: Duplicated Code
    • Smell: Long Function
Powered by GitBook
On this page
  • Three General Approaches to Writing Fast Software
  • 1. Time Budgeting
  • 2. Constant Attention
  • 3. Focused Attention
  1. Chapter 2

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.

PreviousRefactoring & the Wider Software Development ProcessNextGoing Further

Last updated 1 year ago