My project consists of ~350 Swift files and ~40 cocoa pod dependencies.
As soon as the entire project was migrated to Swift 3
, build times have been INCREDIBLY slow and took a little over 3 minutes to completely compile.
I've noticed that if I rebuild after not changing any files, it builds within a reasonable amount of time. However, if I add a new function, it takes the 3+ minutes.
Cocoapods does not seem to be causing the problem as it delays on Compiling Swift source files
state.
I followed this to investigate:
Added the -Xfrontend -debug-time-function-bodies
flag to my Other Swift Flags
in my target's build settings
Build the project
Copied this into terminal and ran pbpaste | egrep '\.[0-9]ms' | sort -t "." -k 1 -n | tail -100
However, I didn't see anything of concern. The file that took the longest to compile was only 250ms. The next closest was 100ms, even if all 350 files took 250ms to compile, that would only be a total of 73 seconds which is way off from the 3+ minute builds I am seeing.
It was never as slow before updating to Xcode 8
and Swift 3
.
Header files Every single compilation unit requires hundreds or even thousands of headers to be (1) loaded and (2) compiled. Every one of them typically has to be recompiled for every compilation unit, because the preprocessor ensures that the result of compiling a header might vary between every compilation unit.
Processing speed matters a lot with optimizations turned on (ca. 10% difference), but on a non-optimized build, SSD is indeed about 3-4 times faster for me than hard disk. Of course the temp file directory where the compiler puts intermediate files should be on SSD too.
In computer science, compile time (or compile-time) describes the time window during which a computer program is compiled. The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concepts related to the context of program execution (runtime).
I created a new project without running the Swift 3
conversion, imported my Swift 3
files, but the build time remains the same.
I've tried SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
, but as soon as you make changes to more than 1 file, the incremental build fails and it triggers a re-build which lasts for more than 4-5 minutes.
I've now re-written my entire code base from Swift 3
to Swift 2.3
. It didn't make any difference, the problem lies with the Xcode 8
compiler.
I can confirm that unchecking these two will alleviate the pain for a while, the Xcode 8
bug does seem to be tied to how it checks dependencies between files.
I've converted my code base to Swift 3
from Swift 2.3
since Xcode 8.2
beta requires it, the beta should include a fix for "Xcode will not rebuild an entire target when only small changes have occurred. (28892475)". Sad to say, they haven't fixed the bug and my compile times are exactly the same with Xcode 8.2 Beta
.
I don't have enough reputation to comment, but I still wanted to share some resources. I've been stuck in this misery for days, upgrading to Swift 3
has been a complete disaster.
I'm using this to track slow files, even though just like you, that's not my problem. Something else in xcode is taking literally 4 minutes to complete: https://github.com/irskep/swift_compile_times_parser https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode
I've also made sure I don't have any lazy vars
or closures
that swift doesn't like. Don't use the + operator
when concatenating strings, etc. see this.
I'll update this answer if I find anything, it's just about impossible to be productive with Swift 3
ATM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With