That “this”-reference is passed in the ECX register every time you perform a member function call to a class, while the register is already set if you make the call from an instance method of the same class. This means switching between different class instances at a high frequency (like in games) is a very CPU intens operation compared to have pure static and/or global functions.
Thats all well and good, except that I just showed you a link to compiler-explorer, showing that the exact same asm is generated for both cases. Including used registeres. Maybe its a matter of calling convention? Maybe you can try to put together some short codesample on godbolt to emphasise what your point is (so that we can eigther see what you mean, or you'll see for yourself that you are wrong).
Shaarigan said:
I don't know about static functions but as soon as you are referencing any static member variable of the class, there will also be some kind of overhead to populate the pointer to the static class memory in heap I guess
I'm pretty sure static class member are just like regular static variables. Again, look at the generated assembly: https://godbolt.org/z/kb9Shp
Foo::X(int): # @Foo::X(int)
add dword ptr [rip + Foo::z], edi
ret
(anonymous namespace)::x(int): # @(anonymous namespace)::x(int)
add dword ptr [rip + (anonymous namespace)::z], 10
ret
(there is a minor difference which I think is a bug in clang, where the compiler inlines the “10” on the global function, even though I specify noinline).
So yeah. Unless you can prove otherwise, your statement are just plainly wrong. Sorry, but thats an important point not to scare people by making them think that just by using a class they get performance degradation.