nickpelling / C_STD

C implementation of the standard container library
MIT License
18 stars 1 forks source link

Check code quality: does making the const jump table extern harm the code quality, e.g. in -flto? #36

Closed nickpelling closed 7 months ago

nickpelling commented 7 months ago

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.

nickpelling commented 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).