Live data from Hacker News

The cost of dynamic vs. static dispatch in C++

eli.thegreenplace.net

71–72 of 72 posts

Re: The cost of dynamic vs. static dispatch in C++

#71
post #15

its interesting to see a break down of this - especially using modern compilers on the intel platform. did you try the intel compiler? for raw low level optimisation it sometimes massively out performs the ms, gcc or clang versions... i'd imagine these problems are worse on ARM chips, and dynamic dispatch is even less effective there - certainly on PPC architectures I've seen much worse performance than on similarly…

thanks again for your comment the other day about memcpy(), I am after finding a deep and rich seam of optimisation out of it!

Re: The cost of dynamic vs. static dispatch in C++

#72

Earlier quoted context omitted.

I've seen interface calls be inlined in action on the modern CLR when looking at disassembly. I don't understand why you would have expected the interface call to be faster than a normal non-virtual call? The interface call always needs a type check before the inlined call body in case of polymorphism; it can't be as fast as a normal call. Or are you saying the interface call is 5x slower than a virtual call? That de…

I expect an inlined interface or virtual call to be the same as an inlined non-virtual call. But since the CLR (4.5, Windows 7 x64, using 32 or 64-bit codegen) won't emit an inlined virtual/interface call for int Add(int, int) -- it's slower. In my simple program doing a loop, calling an Add function on an interface, it is definitely making a function call each time. It unrolls 4 times, and loads the function pointer…

Nice work digging in and figuring out how to trigger it. I fiddled around some earlier and wasn't able to reproduce the behavior I saw before, so I gave up. :) You are correct that the CLR does a poor job optimizing value types, and I probably made the same mistake (i.e. used a struct)
Post reply on HN