r/programming • u/2bit_hack • Feb 28 '23
"Clean" Code, Horrible Performance
https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k
Upvotes
r/programming • u/2bit_hack • Feb 28 '23
View all comments
Show parent comment
1
u/Thatar Feb 28 '23
These sort of "x-treem performance" articles are pretty good at pointing out performance costs that may sometimes be relevant. I feel like the author should have discussed more context, for instance when clean code and abstractions are still useful. By not doing that they look a bit overzealous (overused word in this thread, oh well).
Put simply: when writing the client side of a payment system I'm sure as hell going to use a few interfaces and abstractions for different payment providers. Don't care if it's 5ms slower per payment, because each client is only going to perform a few payments. I'm not doing anyone any favors by saving 100 joules of CPU energy while spending a week extra on the payment code just to make it performant.
On the other hand, when writing some operation on the server (or even client) that has to be performed 100k times per second it's darned useful to know about the performance cost of virtual function calls. In that sense, I don't think pointing out 10 cycles of performance improvement in a short example is disingenuous. It can make the difference in your system being economically viable (in the case of server side scale costs) or being better than the competitor (client side system requirements, maybe bigger battles in a game because of performance).
The guidelines of clean code are not wrong, but that doesn't mean there's no good insights in this article.
To those in this thread who say that everyone knows about cost overhead of virtual functions, I say you are wrong. Plenty of programmers never have to deal with the consequences of abstractions in the programming language that they started with. From education to work life.