swiftc compile time is more slow when using -O than not using
The times you are showing are compilation times, not execution times.
Optimizations take time and the compiler has to work harder to complete them, it's completely normal that compilation takes longer when optimizing the code.
This is in general the intended behaviour, one small disadvantage is the larger executable size that can be produced, but that's generally not an issue
Extremely long compilation times with Swift in Xcode
Try set the following in Build Settings as a workaround. I am assuming you have just one Target.
- Set the Build Active Architecture Only to Yes.
- Set Optimization Level to None [-Onone]
- Add User-Defined setting called "SWIFT_WHOLE_MODULE_OPTIMIZATION" with the value "YES"
- Empty your derived data and build.
You can also then use this tool to analyze any slow compiling Swift files: https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode
I was experiencing build times that were taking 6-7 minutes. I moved away from Cocoapods and started using Carthage which helped for clean builds. Even then builds were still taking 3 minutes. The biggest improvement came with the steps I mentioned above.
Update
Instead of adding the User-Defined setting, on your Debug build set the Optimization Level to 'Fast, Whole Module Optimization'. Then in Other Swift Flags for your debug build add '-Onone'.
Related Topics
How to Update the Constant Height Constraint of a Uiview Programmatically
How Does String Substring Work in Swift
Creating Custom Tableview Cells in Swift
How to Use Special Character in Nsurl
What Is the 'Open' Keyword in Swift
Whither Dispatch_Once in Swift 3
What Is _: in Swift Telling Me
Getting "File Not Found" in Bridging Header When Importing Objective-C Frameworks into Swift Project
Swipe-Able Table View Cell in iOS 9
Swift - Extra Argument in Call
Why Is an Observedobject Array Not Updated in My Swiftui Application
Wait Until Swift For Loop With Asynchronous Network Requests Finishes Executing
String Value to Unsafepointer≪Uint8≫ Function Parameter Behavior
How to Declare an Array of Weak References in Swift
How to Create a Segue That Can Be Called from a Button That Is Created Programmatically