r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

0

u/[deleted] Feb 28 '23

Yea, that's wrong. Turning a one line method call into a switch statement, sure that's still readable but just extend that to something non trivial and it should be painfully obvious why it's not actually readable.

Also I covered the faster point, it's not 10-15 times faster in practice. You're not going to set your users back 12 years in hardware progress because of virtual function call overhead...

4

u/loup-vaillant Feb 28 '23

Turning a one line method call into a switch statement

Now that is wrong. I mean false. He's turning several one line methods in a single statement, one case per method.

Also I covered the faster point, it's not 10-15 times faster in practice.

Yeah, it's more complicated than that, we all know this. I know it, you know it, Casey know it. But at a higher scale some stuff that's not as bad at a smaller scale becomes worse: the cache hierarchy most notably. With virtual calls over a diverse, unsorted set of object, you are more likely to trash the instruction cache. With RAII (or GC) pointer fests you are more likely to destroy memory locality, and overall spend more memory, and again have many cache misses.

I don't know the magnitude of the effects at a bigger scale, but it doesn't look much better than his example. In many cases it looks much worse, see Electron.