Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extremely long compilation times with Swift in Xcode

Tags:

xcode

ios

swift

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.

like image 893
bartlomiej.n Avatar asked Mar 28 '17 10:03

bartlomiej.n


People also ask

Why does Xcode take so long to compile?

Xcode has inbuilt features that allow you to identify functions and expressions that are causing longer compile times. You can specify a compile time limit and identify areas in your codebase that exceed this limit. Open up your project's build settings and add the following flags to your Other Swift Flags .

Why is Xcode running so slow?

Running With Low Disk Space If your disk has less than 20GB remaining, then your overall computer will slow down due to low disk space and you may find it hard to do your regular work on your computer. You must keep your disk space free in order to have a smooth working experience.


2 Answers

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

like image 132
totiDev Avatar answered Nov 09 '22 23:11

totiDev


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

like image 22
ThisIsNotMe Avatar answered Nov 09 '22 23:11

ThisIsNotMe