/O1, /O2 (Minimize Size, Maximize Speed)
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

/O1, /O2 (Minimize Size, Maximize Speed)

Selects a predefined set of options that affect the size and speed of files.


The following table describes /O1 and /O2.

Option Equivalent to Comment

/O1 (Minimize Size)

/Og /Os /Oy /Ob2 /Gs /GF /Gy

Creates the smallest code in the majority of cases.

/O2 (Maximize Speed)

/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy

Creates the fastest code in the majority of cases. (default setting for release builds)

/O1 and /O2 also enable the Named Return Value optimization, which eliminates the copy constructor and destructor of a stack based return value. Consider the following sample. The Test function will not create the copy constructor or destructor. Add output statements to the constructor, destructor and copy constructor to see the effect of the Named Return Value optimization when you run the program. For more information on Named Return Value Optimization in Visual C++, see http://go.microsoft.com/fwlink?linkid = 55900.

// O1_O2_NRVO.cpp
// compile with: /O1
struct A {
   A() {}
   ~A() {}
   A(const A& aa) {}

A Test() {
   A a;
   return a;
int main() {
   A aa;
   aa = Test();

x86 Specific

These options imply the use of the Frame-Pointer Omission (/Oy) option.

END x86 Specific

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

  2. Click the C/C++ folder.

  3. Click the Optimization property page.

  4. Modify the Optimization property.

To set this compiler option programmatically

© 2016 Microsoft