Xcode 8 has some interesting quirks when compiling. I hypothesize that it is part of the type interpolation system.
Takes the following code, for example:
var description: String { get { let desc = String("\(summary ?? "")\n \(narrative ?? "")\n Start: \(start?.dateString ?? "") End: Â \(end?.dateString ?? "")\n \(location ?? "") \n \(htmlLink ?? "")") return desc } }
This is fairly simple string manipulation, where I assume the compiler is converting to something like (I’ve removed the ‘else’ clause for readability):
var description: String { get { var desc = "" if summary != nil { desc = desc + "\(summary!)\n" } if description != nil { desc = desc + "\(narrative!)\n" } if start != nil { desc = desc + "Start: \(start!.dateString) " } if end != nil { desc = desc + "End: \(end!.dateString)\n" } if location != nil { desc = desc + "Location: \(location!)\n" } if htmlLink != nil { desc = desc + "\(htmlLink!)\n" } print(desc) return desc } }
However, while the latter takes about 1.3ms to compile on my machine, the former takes almost 40 seconds.
I imagine this is a temporary glitch, but it’s worth checking to save yourself many minutes per day in compile time.
To check your compile times, add a build setting to your target:
Other Swift Flags $(inherited) "-Xfrontend" "-debug-time-function-bodies"
Then the time taken to compile each file will be available in Xcode’s Report Navigator (the rightmost navigator).
Quick way to discover the culprits:
@nickoneill
Choose â€Copy transcripts for shown resultsâ€, then in Terminal:
pbpaste | egrep ‘\.[0-9]ms’ | sort -t “.” -k 1 -n | tail -10
— Erik Aderstedt (@erikaderstedt) April 27, 2016