3 ms·
I tested this overhead in one of my latest jits. With full PIC and PIE and ASLR (indirect calls via PLT via GOT), I got a 10x overhead over static no PIC, no PI
by rurban 8y ago
I tested this overhead in one of my latest jits. With full PIC and PIE and ASLR (indirect calls via PLT via GOT), I got a 10x overhead over static no PIC, no PIE, all direct near calls.
This was mostly observable on windows, as this was the only secure by default platform then. Linux was 10x faster.
I.e. I got no observable win by replacing the calls with jitted near calls. Nowadays with PIE, PIC and ASLR maybe the jit solution is better again.
One big factor of direct calls vs indirect calls is the CPU i-cache, which preloads the direct call, but not the indirect call.
- tlb 8y agoI believe the branch target buffer on modern x86 hardware predicts and preloads indirect calls too. This analysis claims that Core 2 and later chips predict indirect branches quite well: http://www.agner.org/optimize/microarchitecture.pdf http://www.agner.org/optimize/microarchitecture.pdf
- brandmeyer 8y agoThat's certainly true. But if you are consuming fewer BTB resources by making more direct calls, then the CPU can spend its BTBs accelerating things like predictable virtual function calls and the like.
- rurban 8y agoYes, this. And the BTB is always slower than a direct call. The first call always takes a big hit, only then it will be cached and subsequent calls are about the same speed is direct calls, with 1-2 cycs overhead. The address rarely changes, so it will always be in the first level BTB. But still.