3 ms·
That sounds like an optimization the compiler could / should do for me, if I enable the option. Same with things like struct ordering and / or padding, although
by Cthulhu_ 3y ago
That sounds like an optimization the compiler could / should do for me, if I enable the option. Same with things like struct ordering and / or padding, although that can affect the functionality in subtle ways, because the language gives you too much power at that low level.
- gpderetta 3y agoIt sounds like that, but turns out that those are extremely hard optimizations to do as they require whole program analysis.
- MereInterest 3y agoAlso, because they involve trade-offs. Ideally, a compiler optimization would result in code that is better in every measurable aspect. For example, dead code elimination results in a smaller binary, fewer branch points, and fewer runtime computations. Array padding, on the other hand, requires a larger memory footprint to accommodate the padding. If an optimization is only beneficial in some cases, compiler authors are rightfully wary of enabling it in all cases.
- LorenPechtel 3y agoNo, because the compiler has no way of knowing if you have some reason to care about the layout. 99.99% of the time you don't--but in general it can't know that last .01% where your layout has outside implications.