As my project has grown over the past year, so have its build times. Over the last few months it\'s gone from 4 minutes to around 7 (time includes GitHub pull, unit tests, etc).
Checkout this great post: https://github.com/fastred/Optimizing-Swift-Build-Times
Some contents included:
Since Xcode 9.3 there is a Compilation Mode
called Single File
. It's explicitly said that it can change a game when talking about compilation times in the Xcode release notes
The choice for compiling Swift code by file or by module moved from the Optimization Level setting to Compilation Mode, which is a new setting for the Swift compiler in the Build Settings pane of the Project editor. Previously this choice was combined with others in the Optimization Level setting. Compiling by file enables building only the files that changed, enabling faster builds. Compiling by module enables better optimization.
It truly is a life saver. My incremental compilation times for enterprise project was decreased to couple of seconds. You can try it.
EDIT: In Xcode 12, the same can be referred as Incremental
Turning on the Whole Module Optimization
while adding -Onone
in Other Swift Flags
worked for me, it reduced compilation time to 3 minutes from 10.
Read more here - Speed Up Swift Compilation
I'm using Swift 3
on Xcode 8.3
.
Xcode 8.1/Swift 3.1 adds some relief for projects including some ObjC. Precompiled headers are back! https://swift.org/blog/bridging-pch/
If your project includes a bridging header, this will help. (In Xcode 8.1 beta 4 and later, this is the default; in prior betas add -enable-bridging-pch
to Other Swift Flags
).
Here's an article about benchmarking/speeding up compilation time - swift-profiling.
In case it goes dead here is the tldr:
xcodebuild -workspace App.xcworkspace -scheme App clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep .[0-9]ms | grep -v ^0.[0-9]ms | sort -nr > culprits.txt
You can just run that or add the following flags to your build under the other-swift-flags in build settings:
-Xfrontend -warn-long-function-bodies=100
This will show you which lines are slowing down your compile time.