9

Problem is that when building a Swift app in XCode 8, the source files are compiled quickly, but Copying Swift standard libraries takes the cake - the phase could run for several minutes (usually the whole build is around 4-5 minutes, worst cases have been generously over 10 minutes – used to be under a minute).

Additionally, the signing phase of archive's export is painfully slow, sometimes taking close to half an hour (again, used to be quite quick).

I've scoured the web for answers for days, reinstalled XCode countless times, tried new Swift toolchains, experimented with turning on/off Sierra's iCloud Drive (the derived folder still needs to be hidden from it), tried every build setting that anyone, and their mother, has recommended, made numerous new blank projects, and lost all hope...

So my question is, how can i make it normal?

EDIT: I also have 867 Apple ID keys (same amount of pub-s and priv-s, and the accompanying certificates) in my Mac's Keychain – is there a chance this issue is related to it? Takes a ton of time to go through them and find the correct one to sign with?

Mikk Rätsep
  • 512
  • 7
  • 20
  • I don't know if this applies to you, but it's good advice for avoiding slow compilation times anyway: in your codebase, look for "complex" expressions (such as hairy one-liners) and break them down into several expressions using temp variables. And if you have dictionary literals, help the compiler by stating the type yourself (usually it's better to use type inference but in this case it's better to explicitly give the type) it will ease the compiler's task. – Eric Aya Oct 05 '16 at 12:10
  • Thanks for the tips Eric, they're always useful. I'm using [BuildTimeAnalyzer](https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode) to double-check my code, so that there are no long compiling source-stuff (the longest is 61.8ms, and there's a total of ~20 functions that compile longer than 10ms). – Mikk Rätsep Oct 05 '16 at 13:02
  • This works on Xcode 8.3 swift 3.1 - http://stackoverflow.com/a/40497873/1890317 – uplearned.com Mar 30 '17 at 01:00
  • Thanks Gerard, that's the same approach as the answer below. – Mikk Rätsep Mar 30 '17 at 10:24

3 Answers3

12

So... i finally snapped and deleted all my Apple ID keys (except 1 key pair) from my Keychain (was terrified about breaking things). Now everything builds quickly / normally and i can finally be happy again...

Just to reiterate – make sure you don't have duplicate keys in Keychain.

Mikk Rätsep
  • 512
  • 7
  • 20
  • 1
    had 700+ duplicated keys - removed them all and everything started to work correctly (and fast). xcode provisions the required keys automatically after they were removed. pretty disappointed that xcode got into that strange situation and wasted so much time of mine (and i assume so many other developers) – aporat Oct 25 '16 at 08:43
  • @Mikk Rätsep What do you mean that you have deleted all Apple ID keys, except 1 key paid)? What was this 1 key pair? – bibscy Nov 07 '16 at 12:15
  • @bibscy It means that when i had, for an example, 200 private Apple ID keys, and 200 public Apple ID keys – then i left only 1 private key, and 1 public key. Meaning that i deleted the duplicates. – Mikk Rätsep Nov 07 '16 at 15:09
1

Go to project settings, then Editor > Add Build Setting > Add User-Defined Setting, and add the following:

SWIFT_WHOLE_MODULE_OPTIMIZATION = YES

Adding this flag dropped our clean-build compile times from 7 mins to 65s for a 40KLOC swift project, miraculously. Also can confirm 2 friends have seen similar improvements on enterprise projects.

I can only assume this is some kind of bug in Xcode 8.0## Heading ##

Chris
  • 39,719
  • 45
  • 189
  • 235
  • Is this the same, as setting the **Optimization Level** in *Build Settings - Swift Compiler*? And unfortunately this doesn't work for me... it seems there might be a problem with my computer (as others can build the project quickly)... maybe someone has encountered this before and knows how to fix it (other than format etc.). – Mikk Rätsep Oct 10 '16 at 08:57
0

Besides removing the duplicated keys, I notice a huge improvement in codesign when I changed the access control of the xcode keys to "Allow all applications to access this item"

open "Keychain Access", select the "Keys", and double tap on each key. on the "Access Control" tab you will have the option to select "Allow all applications to access this item".

aporat
  • 5,922
  • 5
  • 32
  • 54
  • Can the same result be accomplished with just giving access to _Xcode_ (or some _codesign_ app it might use)? I personally don't feel comfortable allowing all applications to access my keys. – Mikk Rätsep Oct 31 '16 at 10:34