PERFORMANCE Signal 492
"Clean" Code, Horrible Performance (2023)
A classic “clean-code” shape hierarchy using virtual methods and pointer arrays runs significantly slower than more data-oriented alternatives.
Engineers building performance-critical loops will see higher CPU latency from virtual dispatch and pointer indirection. The example shows that adhering strictly to readability-focused rules can outweigh their maintenance benefits in hot code paths.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
Polymorphic virtual calls prevent inlining and add indirect branches, hurting instruction-pipeline efficiency.
Storing objects as pointers forces non-contiguous memory access, reducing cache locality compared with flat data layouts.
The measured slowdown is confined to tight, high-iteration loops; occasional or non-critical code may still favor the clean-code style.
THE CLUSTER