3 ms·
> If he begins talking about non-virtual methods being more optimized than virtual one, thanks him for his time and try to find someone else. What's your probl
by haberman 17y ago
> If he begins talking about non-virtual methods being more optimized than virtual one, thanks him for his time and try to find someone else.
What's your problem with this answer? Non-virtual methods can be easily inlined, whereas virtual methods (almost always) require:
1. a load (though a hoistable one) from the vtable
2. an indirect branch
3. register re-allocation
4. function call overhead (standard prologue/epilogue)
- VBprogrammer 17y agoThat is only a problem if and only if that method is being called in a very tight loop and its body is not particularly time consuming. A person making optimisations like this without first timing the code or at the very least spending some time introspecting on the pros and cons of doing so would not be someone I wanted to work with!
- pmjordan 17y agoTell that to someone writing a PlayStation 2 game. Using virtual functions without thinking will kill performance on that machine.