Computing optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less memory storage or other resources, or draws less power. The system may be a single computer program, a collection of computers, or even an entire network such as the Internet. Code optimization is an optional phase in compiler design. The last phase of compiler design is the code generation in which the object code (or target code) is generated. The code optimization and code generation process is shown in Fig.
Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code. It involves a complex analysis of the intermediate code and the performance of various transformations, but every optimizing transformation must also preserve the semantics of the program. That is, a compiler should not attempt any optimization that would lead to a change in the program’s semantics. The optimization techniques can improve the code size or speed. There are the following two goals for optimizing the code:
(i) Optimizing for time efficiency (runtime savings)
(ii) Optimizing for memory conservation.
In some cases both optimizations go hand in hand, in other cases, you trade in one for the other. Using less memory means transferring less memory which reduces the time needed for memory transfers. But often memory is used to store precalculated Values avoids the actual calculation at runtime in this case you trade space consumption for runtime efficiency.
- Eliminating the redundancies in a program.
- Rearranging or rewriting the program so that it executes more efficiently.