Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimization levels in Xcode

I have googled this question to clear some basic concepts but didn't find a suitable answer for this.

How many optimization levels are available for code generation in Xcode build setting for the Swift compiler and Apple LLVM (Objective-C)?

like image 937
Animesh Avatar asked Jul 23 '19 04:07

Animesh


People also ask

What is optimization level in compiler?

The degree to which the compiler will optimize the code it generates is controlled by the -O flag. No optimization. In the absence of any version of the -O flag, the compiler generates straightforward code with no instruction reordering or other attempt at performance improvement.


1 Answers

Swift provides four different optimization levels:

-Onone:

This is meant for normal development. It performs minimal optimizations and preserves all debug info.

-O:

This is meant for most production code. The compiler performs aggressive optimizations that can drastically change the type and amount of emitted code. Debug information will be emitted but will be lossy.

-Ounchecked:

This is a special optimization mode meant for specific libraries or applications where one is willing to trade safety for performance. The compiler will remove all overflow checks as well as some implicit type checks. This is not intended to be used in general since it may result in undetected memory safety issues and integer overflows. Only use this if you have carefully reviewed that your code is safe with respect to integer overflow and type casts.

-Osize:

This is a special optimization mode where the compiler prioritizes code size over performance.

You can ready more about these here: OptimizationTips

like image 115
Mukesh Avatar answered Oct 02 '22 02:10

Mukesh