šŸ“Cā€™s explicit layout prohibits some optimizations

Because C almost prescribes a layout of memory (structs and arrays), this prevents compilers from doing some useful optimizations.

For example:

  • Compilers are prohibited to reorder struct fields. Field reordering might decrease required padding and struct size, so less memory is used and more values fit in one cache line, etc.
  • Compilers cannot replace an array of structs with a struct of arrays. This optimizations might improve cache locality or might allow vectorized instructions. It might also eliminate padding.

See also:

Backlinks