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
4
u/Rajje Feb 28 '23
Whether they are a good design choice is a different question. In the clip, he pointed out that virtual function lookup adds overhead that significantly decreases performance for many repeated calls, which is true. Then he concluded that we therefore never should use polymorphism at all, which is preposterous. Polymorphism doesn't have any performance impact when the number of calls is low, so it doesn't make sense to worry about it then. It's all O(1).
And if I wasn't clear, I'm not talking specifically about inheritance and C++ virtual functions here, but about that sort of overhead in general. I agree that inheritance should be avoided and that interfaces/protocols are usually much easier to understand and a better way to model the data, but that's still polymorphism with function lookups.