Reputation: 11184
Configuration:
Compile time: 3 min.
Looks like this configuration is not enough.
HEADERMAP_USES_VFS
to YES
(no change)Build Settings / Architectures / Build Active Architecture Only
to YES
(some improvement)Set defaults write com.apple.Xcode PBXNumberOfParallelBuildSubtasks 4
(8)
(sometimes it's become even worse)
Set optimisation level to -Onone
(no major improvement)
DWARF
instead of DWARF with dSYM File
Find implicit dependencies
from your scheme (no major
improvement)Created a new project and moved all files to the new one (takes too long and give small time improvement)
Change compilator from default to others available (even worse)
Strict rules on how to write fast compiled Swift code (below more details)
I've found a few posts where people describe the same problem: here and here
I guess everyone is waiting for new Xcode 8.2 beta 2 where:
Xcode will not rebuild an entire target when only small changes have occurred. (28892475)
But this is only partially true, I still have long compile time - moved from 6-12 minutes to 3-8. Detailed description of this can be found here and here
Also, I followed all these rules during code writing:
In othe words, don't use any "new cool features" because you'll wait for ages.
One more try - is a workaround described here:
Go to Product -> Scheme -> Edit Scheme. Select Build in left side column and uncheck "Find implicit dependencies" But this flag should remain checked when you are building the project for the first time.
But, this workaround isn't what I'm looking for and this is also can be as a temporary solution.
Swift is a pain not because it's hard to write, but because it's hard to use (at least on some machines).
For comparison: I have a project on Objective-C with 2k classes, and 11 pods - clean compile time is ~30 seconds.
Also I found a lot of opened bugs on Swift performance:
My question is:
Upvotes: 19
Views: 4074
Reputation: 5321
WHOLE MODULE OPTIMIZATION WITH NO DEBUGGING RESTRICTIONS
Just add SWIFT_WHOLE_MODULE_OPTIMIZATION as an user-defined setting with the value YES and your compile times should improve a lot.
This fix was introduced by the developers at Zalando. Shout out to them. https://jobs.zalando.com/tech/blog/improving-swift-compilation-times-from-12-to-2-minutes/?gh_src=4n3gxh1
Upvotes: 1
Reputation: 5321
We improved our compile times a lot by using Carthage instead of Cocoapods to include third party libraries.
Upvotes: 3
Reputation: 6834
This issue has been extremely frustrating for me as well. We've tried several of the solutions you've mentioned and none of them worked.
The one thing that made a significant improvement in compilation time is:
Turning on the Whole Module Optimization
while adding -Onone
in Other Swift Flags
.
See this - Speed Up Swift Compilation
I'm using Swift 3
with Xcode 8.3
.
Upvotes: 8
Reputation: 6157
It's likely you have code optimisation switched on, whilst this is a must for building your release version, for dev builds it isn't particularly important.
What code optimisation does is exactly what it says, it optimises your code to make the end binary that is produced smaller. It does things such as rename variables/methods to single characters etc... Like I said you obviously want this when submitting to the app store but you might not care if the app is larger whilst developing it.
You can turn off code optimisation for development builds by going to Project Settings > Build Settings, searching 'optim', under Swift Compiler - Code Generation set Optimization Level to None [-Onone] for Debug builds.
This should significantly improve your build times.
Upvotes: 2