Whole-Module Optimization in Swift 3

Whole-module optimization is an optimization mode of the Swift compiler. The performance win of whole-module optimization heavily depends on the project, but it can be up to two or even five times.

Whole-module optimization can be enabled with the -whole-module-optimization (or -wmo) compiler flag, and in Xcode 8 it is turned on by default for new projects. Also the Swift Package Manager compiles with whole-module optimizations in release builds.

swift.org/blog/whole-module-optimizations/

Whole-module optimisation boosts Swift code performance by compiling all files in a module together, which allows the compiler to inline functions, specialise generics for specific types, and remove unused code across files.

Without this mode, the compiler handles each file alone, which limits optimisations to within-file boundaries and results in slower generic code or extra runtime checks. This approach can speed up code by up to five times in some cases, and it works well with parallel and incremental builds to keep compile times reasonable.

In Xcode 8, it turns on by default for new projects, and the Swift Package Manager uses it for release builds.


Category:

Tag:

Year: