Why Is Swift Compile Time So Slow

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.

  1. Set the Build Active Architecture Only to Yes.
  2. Set Optimization Level to None [-Onone]
  3. Add User-Defined setting called "SWIFT_WHOLE_MODULE_OPTIMIZATION" with the value "YES"
  4. 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



Leave a reply



Submit