Closed nickpelling closed 7 months ago
I tried this out in Matt Godbolt's compiler explorer, and found that making the jump table extern caused gcc to be unable to do link-time optimisation beyond the table jump. Conversely, it also became clear that where the jump table contents were local, inline functions were able to optimise beyond the jump to the inline function (which then suggested other tickets to raise).
If the big const jump table can be made extern, then container library clients need only include those headers that they're interested in (e.g. std/vector.h, rather than std/container.h). The difference is small now, sure, but it may well be significant if the library grows to include 50 different container implementations.
Conversely, we should check to see if including the big const jump table causes an explosion in executable code size (i.e. are we including all the container implementations rather than just the ones we're interested in?)
Furthermore, we should check to see if the gcc link-time optimisation pass is able to optimise through and past constant jump table references to the code behind.
Finally, we should check to see (with -fno-strict-aliasing?) whether any iterator loops can be auto-parallelised.