Question is as stated in the title: What are the performance implications of marking methods / properties as virtual?
Note - I\'m assuming the virtual methods will <
It's hard to say for sure, because the .NET JIT compiler may be able to optimize the overhead away in some (many?) cases.
But if it does not optimize it away, we are basically talking about an extra pointer indirection.
That is, when you call a non-virtual method, you have to
1 is the same in both cases. As for 2, with a virtual method, you have to instead read from a fixed offset in the object's vtable, and then jump to wherever that points. That makes branch prediction harder, and it may push some data out of the CPU cache. So the difference isn't huge, but it can add up if you make every function call virtual.
It can also inhibit optimizations. The compiler can easily inline a call to a nonvirtual function, because it knows exactly which function is called. With a virtual function, that is a bit trickier. The JIT-compiler may still be able to do it, once it's determined which function is called, but it's a lot more work.
All in all, it can still add up, especially in performance-critical areas. But it's not something you need to worry about unless the function is called at the very least a few hundred thousand times per second.