liveBook · Manning

Optimization

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

Optimization is the deliberate modification of software to improve a measured performance characteristic.

Optimization deliberately modifies software to improve a measured performance characteristic. Start by asking whether faster execution is necessary, which feature needs improvement, and what metric defines “fast enough.” section 1.3.3 section 12.3.2

Use a measurement-led process rather than optimizing by instinct:

  • Define a specific performance target and establish baseline performance before changing the application. section 12.3.2
  • Profile the application to locate where it spends time, then focus effort on the small portion that dominates execution. section 1.3.3 section 12.3.2
  • Change the implementation iteratively, remeasure each change, and compare incremental gains with the added code complexity. section 1.3.3
  • Stop when the application is fast enough; shipping useful features sooner can outweigh marginal speed improvements. section 12.3.2 section 12.9

A focused optimization pass

Suppose one application feature must become faster. Define how much faster it must be, measure its current performance, profile its execution, and improve the code responsible for most of the elapsed time. Repeat the measurement after each change and keep the change only if its benefit justifies its complexity. section 12.3.2 section 1.3.3

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains target-setting, baselining, profiling, focused changes, iteration, and stopping criteria without detailing particular algorithms or profiling tools.
Examples
Uses application features, baseline measurements, execution profiles, the 90/10 rule, and faster hardware or databases as performance considerations.
What it assumes
Assumes familiarity with application development and performance measurement while emphasizing that optimization should begin only after establishing a need.
What you can do after
Evaluate/understand performance work by setting targets, measuring baselines, locating hot code, testing changes, and balancing speed against complexity.
How it connects
Connects optimization with profiling, performance measurement, data structures, caching, databases, application testing, and software delivery.

Also explained in

Compare how 30 books explain optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.