8

I have three iOS projects:

  • First one - 35k Swift LOC, Swift 2.1 (or 2.0?), compiled using Xcode 7.2.3
  • Second one - 15k Swift LOC, Swift 2.3, compiled using Xcode 8.2.1
  • Third one - 15k Swift LOC, Swift 3.0, compiled using Xcode 8.2.1

The compile times for all of these are abysmal (10+ minutes for a clean build), and the development on each one of these is slowing to a crawl.

I have already tried:

  • Using Whole Module Optimization
  • Changing C Dialect to compiler default
  • Analyzing build times for the project and optimizing bottlenecks (a few methods that took 6-10s to compile with array concatenation, nil coalescing operators and such), which shaved like 15 seconds - completely unnoticeable difference
  • HEADERMAP_USES_VFS = YES
  • A few other I don't remember now

I'm working on a Mac mini Late 2014 with an SSD, 8GB RAM & 2.6ghz i5, if that matters.

Anyone knows what might cause that, what to do with that or even any workarounds for now? From what I've read on SO and other places, it seems like an unresolved compiler issue.

EDIT: Yes, I'm using Cocoapods for dependencies. I'll try moving to Carthage and see what happens.

7
  • Are you using cocoapods? Commented Mar 28, 2017 at 10:29
  • 1
    Have you seen this: thatthinginswift.com/debug-long-compile-times-swift ? Commented Mar 28, 2017 at 10:36
  • Yes, I'm using cocoapods, and yes, I have seen that article. It's not connected to type inference issues. I've already sorted out code bottlenecks. Commented Mar 28, 2017 at 10:40
  • @user7779221 That article is not about type inference issues. It's about finding out which method body takes too long to compile. Commented Mar 28, 2017 at 10:49
  • Did you tried running it on a different mac? Are other projects working fine on the same mac you are compiling these codes? For example: if you tried to compile FlappySwift from GitHub, how are those building times? Commented Mar 28, 2017 at 10:54

2 Answers 2

6

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'.

Sign up to request clarification or add additional context in comments.

7 Comments

I tried the steps above, but I haven't tried moving to Carthage yet, that might help. Thanks!
Did the steps not help to improve compile times? In my experience that gave the biggest boost to Swift compile times. It's important to not use "Whole Module Optimization" which you mentioned and instead do it the way I described.
I haven't tried setting SWIFT_WHOLE_MODULE_OPTIMIZATION from User-Defined settings, just as code optimization setting. I'll try that as well.
It's important to set the code optimisation setting to none as mentioned in the steps and then add the user defined version. You can repeat the 3 steps for all the modules in your project.
Wow! This seemed to do the trick. It went down to about 2.5 minute, without using Carthage. Thanks a lot! You don't even know how much I appreciate that!
|
1

It's an open issue on swift's site: https://bugs.swift.org/browse/SR-6037 Hopefully they'll fix it soon.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.