Code Size Optimization Mode in Swift 4.1

The Swift compiler comes with powerful optimizations. When compiling with -O the compiler tries to transform the code so that it executes with maximum performance. However, this improvement in runtime performance can sometimes come with a tradeoff of increased code size. With the new -Osize optimization mode the user has the choice to compile for minimal code size rather than for maximum speed.

swift.org/blog/osize/

Swift 4.1 adds a new optimisation mode called -Osize. This mode helps reduce code size by 5 to 30 percent in some projects. It does this by limiting function inlining and using helper functions for certain patterns. The mode works with both single-file and whole-module compilation. Performance drops are small, often below 5 percent, but -O remains better for speed-critical code.


Category:

Tag:

Year: