liveBook · Manning

90/10 rule

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

The 90/10 rule of code optimization is the heuristic that roughly 90 percent of execution time is spent in roughly 10 percent of the code.

The 90/10 rule is a practical optimization heuristic: roughly 90 percent of an application's execution time is spent in roughly 10 percent of its code. It points optimization toward measured hotspots rather than evenly distributing effort across the codebase. section 1.3.3 section 12.3.2

Apply the rule as part of a measured optimization process:

  • Set a specific performance target instead of asking generally for the application to become faster. section 12.3.2
  • Establish baseline performance and profile the application to locate where it spends time. section 1.3.3 section 12.3.2
  • Optimize the small portion consuming most of the time, then profile again to verify the change. section 1.3.3 section 12.3.2
  • Balance small performance gains against added complexity, and stop when the application is fast enough to ship. section 1.3.3 section 12.3.2

A measured optimization loop

An application needs to run faster, but its requirement is not yet precise. Define the relevant performance metric, measure the current baseline, and profile execution. If the measurements identify a small area consuming most of the time, concentrate optimization there and measure again. If the target is reached, stop; otherwise, compare the gain with the complexity introduced by further changes. Infrastructure changes, such as a faster computer, more bandwidth, or a higher-capacity database, may offer a less expensive alternative. section 1.3.3 section 12.3.2

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

How deep it goes
Defines a heuristic and embeds it in profiling, iterative measurement, trade-offs, and stopping criteria.
Examples
Uses execution-time measurements, performance metrics, faster computers, wider bandwidth, and higher-capacity databases as optimization reference points.
What it assumes
Assumes an application with a measurable speed requirement and teaches optimization through target-setting and baseline measurement.
What you can do after
Diagnose performance with profiling, focus optimization on measured hotspots, compare gains, and stop when the target is met.
How it connects
Connects performance targets and baseline measurement with profiling, caching, data structures, infrastructure, and shipping decisions.

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.