Ryan Peterman
Dogmatic clean code rules ruin software performance because hiding concrete types behind virtual dispatch prevents compilers from inlining and auto-vectorizing code.
AI-assisted summary of "Clean Code", Horrible Performance | Casey Muratori — original source. Check the original for full context.
Source published:
Key ideas
- Casey Muratori explains that the primary performance cost of 'Clean Code' dogma is not the vtable dispatch itself, but how virtual boundaries prevent compilers from inlining, unrolling loops, and applying SIMD vectorization. (0:00)
- Foundational software literature, including Clean Code and Refactoring, frequently dismisses performance trade-offs under the guise of avoiding premature optimization, leading to systemic architectural degradation. (5:00)
- The rise of generative AI makes performance awareness essential, as developers must understand underlying machinery to properly direct AI coding agents away from bloated and inefficient architectural patterns. (5:00)
- Acquiring baseline hardware and performance intuition requires minimal training that permanently equips developers to delay concrete optimizations safely without architecting themselves into dead ends. (10:21)
Detailed notes
## Background Published by Ryan Peterman on YouTube on October 7, 2026, this video features game developer and computing educator Casey Muratori. The excerpt is taken from a broader conversation exploring surprising discoveries from computer history, the root causes of bad software, and Muratori's career path.
## TL;DR Casey Muratori explains why dogmatic 'clean code' principles—specifically tiny functions hidden behind dynamic virtual dispatch—devastate compiled code performance by preventing compiler inlining, loop unrolling, and SIMD vectorization. He critiques influential literature like Clean Code and Refactoring for fostering a culture that treats performance as an afterthought under the guise of avoiding premature optimization. Instead of blindly applying rigid readability rules or leaving architecture to chance, Muratori argues that engineers and developers directing AI coding agents need basic hardware awareness so they can make conscious architectural trade-offs without painting codebases into unrecoverable corners.
## Atmosphere & style The exchange carries the grounded, thoughtful intensity of a pragmatic systems programmer deconstructing widely accepted software orthodoxy. Muratori speaks with clear-eyed conviction and technical precision, patiently distinguishing between sensible code hygiene and destructive architectural dogma without slipping into sensationalism. Peterman provides an engaged, reflective sounding board, prompting an illuminating discussion that feels like an indispensable reality check against modern software bloat.
## Bulletin - [00:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=0s) Casey Muratori explains that the primary performance cost of 'Clean Code' dogma is not the vtable dispatch itself, but how virtual boundaries prevent compilers from inlining, unrolling loops, and applying SIMD vectorization. - [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) Foundational software literature, including Clean Code and Refactoring, frequently dismisses performance trade-offs under the guise of avoiding premature optimization, leading to systemic architectural degradation. - [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) The rise of generative AI makes performance awareness essential, as developers must understand underlying machinery to properly direct AI coding agents away from bloated and inefficient architectural patterns. - [10:21](https://www.youtube.com/watch?v=czr1L3JocOI&t=621s) Acquiring baseline hardware and performance intuition requires minimal training that permanently equips developers to delay concrete optimizations safely without architecting themselves into dead ends.
## Key takeaways - [00:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=0s) The phrase 'clean code' lacks universal consensus; Muratori's critique focuses specifically on the dogmatic rules presented in Robert C. Martin's book Clean Code. - [00:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=0s) Mandating microscopic 4- to 5-line functions interacting through abstract base classes strips compiled languages like C++ of the type information needed for cross-boundary optimization. - [00:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=0s) Branch prediction can make virtual function calls relatively cheap, but the inability of the compiler to see concrete types causes massive optimization loss by blocking inlining and auto-vectorization. - [00:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=0s) Writing 30- to 50-line functions with concrete types known at compile time preserves high readability and maintainability without incurring severe optimization penalties. - [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) Prominent engineering texts frequently misapply adages like 'premature optimization is the root of all evil' to rationalize omitting performance considerations entirely from software education. - [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) Genuine engineering requires intentionally weighing trade-offs and accepting known performance compromises, rather than pretending execution efficiency can always be handled later. - [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) Engineers using generative AI models must possess low-level performance literacy to avoid prompting or accepting generated code structured around inefficient patterns. - [09:01](https://www.youtube.com/watch?v=czr1L3JocOI&t=541s) Grasping basic distinctions such as network latency versus network throughput enables engineers to structure code for batching upfront rather than producing purely serial architectures. - [09:01](https://www.youtube.com/watch?v=czr1L3JocOI&t=541s) Cultivating an accurate mental model of how hardware operates is the highest-leverage skill for preventing architectural choices that require complete codebase rewrites. - [10:21](https://www.youtube.com/watch?v=czr1L3JocOI&t=621s) Performance training is a one-time learning investment that functions as an ongoing internal alarm bell whenever a proposed design lacks a viable path to efficiency. - [10:21](https://www.youtube.com/watch?v=czr1L3JocOI&t=621s) Maintaining a clear conceptual roadmap for future performance improvements allows developers to safely defer actual optimization work without painting themselves into a corner.
## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=0s) Deconstructing "Clean Code" and the Dynamic Dispatch Trap
Ryan Peterman brings up an earlier point of discussion regarding the trade-off between writing performant code versus maintainable code, pointing specifically to Casey Muratori's well-known video titled `"Clean Code", Horrible Performance`. Ryan asks why Casey placed the phrase "clean code" in quotation marks and what he meant by that framing. Casey explains that terms like "clean code" or "object-oriented programming" are inherently slippery because they mean vastly different things depending on who you ask; it is virtually impossible to find two programmers who will agree on what is truly clean. The quotation marks were deliberate because he was targeting the specific dogmas laid out in Robert C. Martin's book *Clean Code*, rather than the abstract concept of clean, readable software.
The core ideology promoted in the book rests on specific rules: functions should be absurdly tiny—often four to five lines long—and code should interact almost entirely with abstract base classes through dynamic dispatch, deliberately remaining oblivious to concrete types. Casey points out that when applying this philosophy to compiled languages like C++, it becomes an absolute recipe for disaster. While a four-line function is completely harmless if the compiler can see it and inline it, forcing tiny functions behind virtual function calls blinds the compiler. The compiler cannot deduce concrete types at compile time or across module boundaries (absent aggressive link-time code generation), which prevents it from merging the code paths together.
```mermaid flowchart TD accTitle: Compiler Optimization vs Virtual Dispatch accDescr: Diagram illustrating how visible types enable compiler optimizations while virtual dispatch blocks them.
subgraph Direct["Concrete Types (Compile-Time Visible)"] A["Caller Function"] --> B["Known Function Body"] B --> C["Optimization Engine"] C --> D["Inlining & Merging"] C --> E["Loop Unrolling"] C --> F["SIMD / Vectorization"] end
subgraph Dynamic["Virtual Dispatch ('Clean Code' Rule)"] G["Caller Function"] --> H["Dynamic Dispatch / Vtable"] H --> I["Unknown Target Type"] I --> J["Compiler Blocked"] J --> K["No Inlining"] J --> L["Scalar Execution Only"] end ```
Casey clarifies a widespread misconception that arose from his video: the real performance catastrophe is not merely the CPU cycle cost of the virtual function call itself, which can actually be relatively cheap if branch prediction succeeds. The true disaster is the severe downstream optimization penalty. When a compiler cannot see through a virtual boundary, it cannot inline, cannot eliminate redundant overhead, cannot unroll loops, and cannot widen operations to utilize SIMD (vectorization). Casey stresses that he is not advocating against maintainability, but rather rejecting arbitrary and damaging dogma. Writing functions that are 30 to 50 lines long is perfectly maintainable, and keeping concrete types known at compile time does not make code difficult to read.
- **Book guidelines criticized**: Strict mandates that functions should be 4–5 lines long and operate strictly on dynamic/opaque base classes without knowing concrete types. - **Root cause of slowness**: The inability of the compiler to inline code and see the full pipeline, which completely blocks dead code elimination, loop unrolling, and auto-vectorization (SIMD). - **Virtual call cost vs. optimization loss**: The vtable branch itself carries a small to moderate overhead depending on branch prediction, but the missed compiler optimization optimizations cost orders of magnitude more.
---
[05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) Balancing Trade-offs, Software Literature, and the AI Coding Era
Ryan recalls how, early in his college years, people routinely advised him to read *Clean Code*, and asks whether Casey would explicitly recommend software engineers steer clear of it. Casey responds that the book is more of a mixed bag; he agrees with standard baseline advice like giving variables clear, intuitive names. His primary frustration is that prominent software engineering literature routinely presents rules of thumb while totally ignoring the severe performance costs they incur. He observes a pervasive cultural tendency to pretend performance does not exist, frequently hiding behind misapplied adages like "premature optimization is the root of all evil" to justify leaving performance entirely out of the curriculum.
Casey notes that this evasive attitude is everywhere in foundational engineering literature—pointing out that Martin Fowler's influential book *Refactoring* essentially begins by brushing off performance concerns, assuming they will usually just sort themselves out. Casey rejects this worldview outright. Software development is fundamentally about trade-offs: making an informed decision where an engineer acknowledges, "This may be a serious performance problem for us, but I think that's okay because it won't harm the product," is genuine engineering. Blindly pretending that performance can simply be deferred until the very end is an entirely different, flawed methodology.
Casey argues that understanding these trade-offs has become even more critical in the era of generative AI. While he does not personally work with AI tooling, developers are now in the position of prompting and directing AI coding agents. If an engineer has no awareness of how code structure impacts execution speed, they cannot instruct models to avoid slow, bloated architectural patterns. When Ryan asks what lightweight, high-value performance principles developers should keep in mind, Casey states that the single most vital component is simply basic awareness—understanding the underlying machinery before making design decisions.
- **Industry literary blind spots**: Influential texts such as *Clean Code* and *Refactoring* often dismiss performance as a non-issue that can be solved later, blinding engineers to systemic architectural degradation. - **The true definition of engineering**: Consciously weighing trade-offs and accepting known performance hits when justified by business needs, rather than ignoring performance outright. - **Relevance in the AI era**: Directing AI models to write and refactor code requires a clear understanding of low-level performance implications, otherwise bad idioms will be generated at scale.
[09:01](https://www.youtube.com/watch?v=czr1L3JocOI&t=541s) Hardware Awareness and Architectural Decisions
Understanding the performance characteristics of the underlying hardware—including what a network looks like if one is involved—comes down to basic awareness more than anything else. As Casey Muratori explains, "a little bit of awareness can go a very long way." For example, simply grasping the fundamental difference between network latency and network throughput allows a developer to make upfront decisions to structure code so that operations are batched properly. Without that foundational concept, a team can get very far into a project only to realize that every part of their design operates serially, cannot be accelerated over a network at all, and is never going to run reasonably.
Because of this, the lowest-hanging fruit for any programmer is simply getting some basic education in performance: learning how a machine actually works, what makes it fast or slow, and what it struggles with versus what it handles easily. Keeping that mental model in the back of your head makes you very unlikely to make the kinds of architectural decisions that will be hard to undo later.
```mermaid flowchart TD accTitle: Impact of Hardware Awareness on Architecture accDescr: Compares how understanding versus ignoring hardware realities like network latency versus throughput affects software design and rework. subgraph Aware["With Performance Awareness"] A1["Understand latency vs. throughput"] --> A2["Structure code to batch operations"] A2 --> A3["Clear path to optimize later"] end subgraph Unaware["Without Performance Awareness"] U1["Ignore network characteristics"] --> U2["Design purely serial operations"] U2 --> U3["Cannot accelerate over network"] U3 --> U4["Forced to scrap and rewrite"] end ```
[10:21](https://www.youtube.com/watch?v=czr1L3JocOI&t=621s) The Permanent Value of Performance Training
Acquiring this foundational knowledge is by far the "highest-impact, lowest-cost thing you can do" because you only have to do the training once. Once you understand how to think about performance, that intuition stays with you forever. It acts as a constant internal alarm bell whenever you are designing a system, prompting you to pause and think, "I don't see the path towards this running well," which serves as your cue to stop and rethink how decisions are being made.
Importantly, having this intuition does not mean you have to optimize everything immediately. As long as you can clearly see the path for how the system will eventually be optimized, you can safely delay most actual optimization work. By making the right upfront architectural tradeoffs with that path in mind, you avoid painting yourself into a corner where your only remaining option is to scrap the entire codebase and rewrite it from scratch.
## Notable quotes > [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) premature optimization is the root of all evil — Casey Muratori
> [05:00](https://www.youtube.com/watch?v=czr1L3JocOI&t=300s) This may be a serious performance problem for us, but I think that's okay because it won't harm the product, — Casey Muratori
> [09:01](https://www.youtube.com/watch?v=czr1L3JocOI&t=541s) a little bit of awareness can go a very long way. — Casey Muratori
> [10:21](https://www.youtube.com/watch?v=czr1L3JocOI&t=621s) highest-impact, lowest-cost thing you can do — Casey Muratori
> [10:21](https://www.youtube.com/watch?v=czr1L3JocOI&t=621s) I don't see the path towards this running well, — Casey Muratori
## Mentioned Ryan Peterman, Casey Muratori, "Clean Code", Horrible Performance, Robert C. Martin, Clean Code, C++, SIMD, Martin Fowler, Refactoring
## Video description Casey Muratori is a video game developer and programming creator also known for his talks about the history of software and computing. We talked about surprising parts he found while digging through computer history, where bad code comes from, and his career story.
Watch the full conversation: https://www.youtube.com/watch?v=jHLbL1Eg4gM
[Source](https://www.youtube.com/watch?v=czr1L3JocOI)