Optimizer Configuration: General Level
Let's learn how to configure a general level optimizer.
Configuring the optimizer
The optimizer will analyze the output of previous stages and use a multitude of tricks, which programmers would consider dirty, as they don't adhere to clean-code principles. That's okay – the critical role of the optimizer is to make code performant (that is, use few CPU cycles, few registers, and less memory). As the optimizer goes through the source code, it will transform it heavily so that it almost becomes unrecognizable. It turns into a specially prepared version for the target CPU.
Role of the optimizer
The optimizer will not only decide which functions could be removed or compacted; it will also move code around or even significantly duplicate it! If it can determine with full certainty that some lines of code are meaningless, it will wipe them out from the middle of an important function (we won't even notice). It will reuse memory so that numerous variables can occupy the same slot in different periods of time. And it will transform our control structures into totally different ones if that means it can shave off a few cycles here and there.
Get hands-on with 1400+ tech skills courses.