Optimization (Delphi)

From RAD Studio

Go Up to Delphi Compiler Directives (List) Index

Type

Switch

Syntax

{$O+} or {$O-} {$OPTIMIZATION ON} or {$OPTIMIZATION OFF}

Default

{$O+} {$OPTIMIZATION ON}

Scope

Local (except Global for DCCIOSARM64 compiler)


The $O directive controls code optimization. In the {$O+} state, the compiler performs several 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.

Except in certain debugging situations, you should never 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.

Note:
  • 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 64-bit iOS Device (and thus use the DCCIOSARM64 compiler), the $O directive has global scope. The compiler does not generate any warnings or hints, but the optimizer uses the last setting if multiple $O options appear in a single source file.

Selective Compiler Optimization

RAD Studio introduces a compiler directive that allows users to enable specific optimizations.

{$OPTIMIZATION <feature> ON|OFF}

At this time, this has been enabled only for CMOV optimization via the following directive:

{$OPTIMIZATION CMOV ON|OFF}


See Also