Compiler Options as Tuning Tools

team bbl


Compilers often "know" the machine architecture and processor better than the developer, performing as a matter of course such optimizations as dead code elimination, loop unrolling, branch optimization, and function inlining. In many cases, the programmer finds that all the major and obvious bottlenecks identified via profiling are resolved by using the optimizations provided by the compiler.

In gcc, the general level of optimization is controlled by the O flag. At its most basic level, -O1, the flag takes the most general steps to reduce code size and execution time. O2 causes gcc to perform nearly all optimizations that do not involve a space-speed trade-off (such as loop unrolling or function inlining). O3 turns on such additional optimizations as function inlining and register renaming. We recommend an interative process of increasing optimization/profiling cycles to determine the best level for your application. This is because it is possible, even with well-written code, for a higher level of compiler aggressiveness in optimization to hurt a piece of code's performance rather than help it. Sometimes, this is a matter of what the more aggressive optimizer is looking for as opposed to what the code is actually trying to do. A reading of the performance options section of the gcc manual reveals many additional options, most of which are more suitable for use after a particular code section has been analyzed and its problems made clear.

Basic Performance Tuning

Following are the basic steps in tuning a program:

1.

Create a baseline by doing a plain compile with profiling on and analyzing it.

2.

Turn on the base level of optimization for your compiler (still profiling).

3.

Measure again, and identify the bottlenecks in your program.

4.

Tune the bottlenecks and measure. Remove tuning that doesn't help, as measured through profiling.

5.

Turn on the next level of compiler optimization.

6.

Repeat from Step 3.

Tuning your application for performance is a methodical and sometimes repetitive process that nonetheless can give great rewards in program efficiency.

One Word About Compiler Optimizations

Sometimes at the higher levels of compiler optimization, you may see a decrease in performance instead of an increase for a given module. Compilers are not perfect, and in these cases a closer examination of the code itself is warranted to see what can be done to "help" the compiler see what needs to be optimized through making the code simpler or using a different algorithm in that section.

Following are some things to consider when developing code. Giving some consideration to your code can make all the difference.

    team bbl



    Performance Tuning for Linux Servers
    Performance Tuning for Linux Servers
    ISBN: 0137136285
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net