by mostlylurks · 4y ago · 0 comments
The switch/jmp table can be optimized to be inline, vtable will likely incur a stack frame, plus usually 3 indirections.
When you have a closed set of types, then you know all cases for branching, in polymorphism you lose this power -- it's open ended.
This is another reason why languages should have exhaustive pattern matching with sum types.
These don't matter much for big heavy functions, but tiny ones can seriously benefit from being inlined.
I have heard elsewhere that "game objects are just an index into a bunch of arrays for all the object properties" is fairly common practice, but well I don't write games myself.