The Origin and Evolution of "Premature Optimization is the Root of All Evil"

1. Origination (Who and Where)

The quote was originated by the pioneering computer scientist Donald E. Knuth. It made its first published appearance in December 1974 in Knuth's seminal paper, "Structured Programming with go to Statements," published in the ACM Computing Surveys (Volume 6, Number 4, page 268).

The phrase was introduced in the following complete context:

"Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."

During the same month (December 1974), Knuth also used a slight variation of the phrase in his ACM Turing Award lecture, "Computer Programming as an Art," stating: "premature optimization is the root of all evil (or at least most of it) in programming".

2. Circumstances of Origination

The quote was born during a period of fierce philosophical debate in early computer science known as the "structured programming" revolution. In 1968, Edsger W. Dijkstra published a famously uncompromising letter titled "Go To Statement Considered Harmful," arguing that the unrestricted use of goto statements created unmaintainable "spaghetti code".

In 1972, Dijkstra, C.A.R. Hoare, and Ole-Johan Dahl published the book "Structured Programming," which cemented these concepts into a complete programming paradigm. Donald Knuth read this foundational text and, in 1973, wrote a formal 40-page review of it. His 1974 paper, where the famous quote originates, was the culmination of his thoughts on their book. Knuth sought to find a middle ground: he conceded that Dijkstra and Hoare were generally right about maintaining readability, but argued that for the most computationally intense loops of a program, developers constrained by 1970s hardware still needed to utilize every trick available to achieve necessary speeds.

3. Meaning and Intent: The Empirical 97% / 3% Split

Contrary to modern interpretation, Knuth was not advocating against optimization. His figures of 97% and 3% were not mere rhetorical flourishes; they were rooted in empirical profiling studies, including his own analyses of Fortran programs. These studies demonstrated that execution time is highly disproportionate to code volume.

The "97%" represents the vast majority of a codebase that executes infrequently. In these areas, micro-optimizations (like unrolling loops or manually inlining functions) yield almost zero measurable benefit while severely damaging code readability. The "3%" represents the true "inner loops" and processing bottlenecks. Knuth's core argument was an attack on programmer intuition. "Premature" optimization meant twisting code to be fast before the programmer had actually utilized measurement tools (profilers) to prove that the specific section belonged to the critical 3%.

Therefore, the originator's intent was a strict two-step mandate:

  1. Write clean, logically structured code for the 97% of the application, completely ignoring small efficiencies.
  2. Use careful, empirical profiling to locate the "critical 3%"—the true hotspots—and aggressively optimize them without hesitation.

4. Conflicting Stories, Mistakes, and Exaggerations

The history of this quote is fraught with prominent misattributions and modern misinterpretations:

A. The Misattribution to C.A.R. Hoare and Dijkstra

The quote is frequently attributed to Sir Tony (C.A.R.) Hoare or Edsger Dijkstra. Surprisingly, the source of this widespread error was Knuth himself. Fifteen years after coining the phrase, Knuth published a paper titled "The Errors of TeX" (1989). In it, his memory failed him, and he wrote: "But I also knew, and forgot, Hoare's dictum that premature optimization is the root of all evil in programming".

In January 2004, programmer Hans Gerwitz emailed Tony Hoare to ask about the origins. Hoare explicitly denied originating it, replying: "I'm sorry I have no recollection how this quotation came about. I might have attributed it to Edsger Dijkstra...". Because Hoare, Dijkstra, and Dahl co-authored the 1972 book that prompted Knuth's 1974 paper, it is completely understandable why Knuth's memory entangled the quote with Hoare. Following Hoare's denial, developers contacted Knuth directly, who confirmed he had actually coined it himself and misremembered in 1989.

B. The "Thought-Terminating Cliché" Exaggeration

Over the decades, the context ("We should forget about small efficiencies, say about 97% of the time...") was stripped away. Today, the isolated phrase is frequently used as a "thought-terminating cliché" by developers seeking to justify entirely ignoring performance, system architecture, or memory usage in favor of rapid development. Modern critics note that this completely betrays Knuth's intent, effectively weaponizing the quote to excuse bloated, sluggish software.

5. Chronology of Events

References

  1. Dijkstra, E.W., Hoare, C.A.R., & Dahl, O.J. Structured Programming. Academic Press, 1972.
  2. Knuth, Donald E. "Structured Programming with go to Statements." Computing Surveys, Vol. 6, No. 4, December 1974, pp. 261-301.
  3. Knuth, Donald E. "Computer Programming as an Art" (1974 Turing Award Lecture). Communications of the ACM, Vol. 17, No. 12, December 1974, pp. 667-673.
  4. Knuth, Donald E. "The Errors of TeX." Software—Practice & Experience, Vol. 19, Issue 7, July 1989, pp. 607-685.
  5. Gerwitz, Hans. "Premature optimization is the root of all evil." August 12, 2004. Documentation of correspondence with C.A.R. Hoare.
  6. Shreevatsa. "Premature optimization is the root of all evil." The Lumber Room, May 16, 2008. Analysis of the Knuth/Hoare timeline.
  7. Dijkstra, Edsger W. "Go To Statement Considered Harmful." Communications of the ACM, Vol. 11, No. 3, March 1968, pp. 147-148.