Optimization (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index








Local (except Global for DCCIOSARM and DCCIOSARM64 compilers)

The $O directive controls code optimization. In the {$O+} state, the compiler performs a number of code optimizations, such as placing variables in CPU registers, eliminating common subexpressions, and generating induction variables. In the {$O-} state, all such optimizations are disabled.

Other than for certain debugging situations, you should never have a need to turn optimizations off. All optimizations performed by the Delphi compiler are guaranteed not to alter the meaning of a program. In other words, the compiler performs no "unsafe" optimizations that require special awareness by the programmer.


  • The $O directive can only turn optimization on or off for an entire procedure or function. You cannot turn optimization on or off for a single line or group of lines within a routine.
  • For iOS applications that target the 32-bit iOS Device (and thus use the DCCIOSARM compiler), and for iOS applications that target the 64-bit iOS Device (and thus use the DCCIOSARM64 compiler), the $O directive has global scope. The compiler does not generate any warning or hint messages, but the optimizer uses the last setting, if multiple $O options exist in a single source code file.
    However, for iOS applications that target the iOS Simulator (and use the DCCIOS32 compiler), the $O directive has local scope, as do the Delphi desktop compilers.

See Also