4 ms·
I absolutely agree that modern programming languages need generics, but this particular issue with qsort is only a problem if you're not using link-time optimiz
by pcwalton 4y ago
I absolutely agree that modern programming languages need generics, but this particular issue with qsort is only a problem if you're not using link-time optimization (LTO). If you care about performance, you should be using LTO (all the FAANGs use it extensively, for example). And if you do use LTO, then the call overhead of qsort is eliminated via inlining.
As an example, here's musl's qsort() implementation paired with a use in Godbolt. (I couldn't actually use LTO on Godbolt because it doesn't LTO the standard library, but the effect would be the same.) Note that there are no call instructions at all and the compareme() function is completely eliminated by the optimizer: https://godbolt.org/z/6W8Wxf6xP https://godbolt.org/z/6W8Wxf6xP
- gpderetta 4y agoFor LTO, you also need to statically link with your libc which is seldom done (do FAANGs do it?). Or write/duplicate qsort in your own library, which is more likely.