The main issue that is mentioned by others but not called out enough is that -O3
does nothing at all in Swift (and never has) so when compiled with that it is effectively non-optimised (-Onone
).
Option names have changed over time so some other answers have obsolete flags for the build options. Correct current options (Swift 2.2) are:
-Onone // Debug - slow
-O // Optimised
-O -whole-module-optimization //Optimised across files
Whole module optimisation has a slower compile but can optimise across files within the module i.e. within each framework and within the actual application code but not between them. You should use this for anything performance critical)
You can also disable safety checks for even more speed but with all assertions and preconditions not just disabled but optimised on the basis that they are correct. If you ever hit an assertion this means that you are into undefined behaviour. Use with extreme caution and only if you determine that the speed boost is worthwhile for you (by testing). If you do find it valuable for some code I recommend separating that code into a separate framework and only disabling the safety checks for that module.