15 ms·
This is one of those things that sounds better than it really is. The timing used here in this post is ns per call, which somewhat obfuscates what's going on.
by jcranmer 8y ago
This is one of those things that sounds better than it really is.
The timing used here in this post is ns per call, which somewhat obfuscates what's going on. A better metric would be clock cycles of overhead, because the differences here are only around 2-3 clock cycles. In other words, the potential savings is going to be drowned out by jitter caused by things like the processor deciding to service interrupts, or your hyperthread partner doing work. If the relevant code is so hot that the cost is showing up in profiles, then very likely, the fact that a function call is going through the PLT versus being directly called is not going to be the thing that makes the most difference: it's the fact that you're making the function call in the first place.
- ajross 8y agoWell, sure, but by the same measure and for the same reasons, "clock cycles" are not a deterministic measure of software performance, while "nanoseconds" are, by definition. The test can't easily control for cache effects (which are vastly bigger in aggregate than IRQ or SMT effects, FWIW), so it doesn't try and assumes everything averages out, and it does. The reason the effect seems bigger than it is is that for all but the most trivial leaf functions, PLT indirection just isn't a big deal. Never has been, isn't now, never will be. It's a cool trick that a JIT can skip that step, but there are bigger fish to fry.
- achamayou 8y agoAnd the most trivial cases will be inlined more often than not.
- cryptonector 8y agoThe author mentions that for real things the PLT and indirect call overhead is in the noise, which makes you wonder what the point of all of this is. Besides, the headline is click-bait, and the contents is obnoxious: it's all about static vs. dynamic linking vs. using dlopen()/dlsym(). There's nothing in TFA specific to C, for example, nor even to Lua, as any statically-linked program written in any high-level programming language with an FFI to C or assembly will evince this performance advantage over a dynamically-linked version of the same.
- BeeOnRope 8y agoThis doesn't seem right. Many languages have only a single way to do FFI (e.g., usually via calling a dynamic object) so the concept of "statically linked FFI" doesn't even apply to many languages. The whole GOT/PLT thing is kind of C/C++ specific, since that's compiled into the calling code, and supports specific C ABI features like symbol interposition, and so is not a necessary component of calling a dynamic library. Especially JIT-compiled languages don't really need either of the features the GOT or PLT offer. I think the main performance are really (1) dynamically linked C/C++ with GOT + PLT, (2) statically linked C/C++ and then (potentially) separate categories for the FFI mechanism for various high level languages, which may happen to coincide with (1) or (2) or have some other behavior. Certainly the very slow results for some languages indicate that they are doing something other than a plain call via mechanisms (1) or (2).