I’m just about blue in the face complaining about it, too. So bear with me if you’ve heard all this before. I promise I’ll stop ranting after this post, and move on to happier topics ;-).
Slow as molasses
I realize this may be caused by a combination of issues. Perhaps the Swift compiler is not optimized yet. Perhaps it’s just the generally awful state of the Xcode toolchain. Whichever the culprit, the end result remains equally as enervating… I am referring to Swift’s complete and utter slowness with regards to code compilation.
If you’ve done any serious Swift development of late, you know that incremental Swift compilation is a lie. All but the most trivial changes trigger complete rebuilds, resulting in insane waiting times between builds. Apple supposedly set out to resolve this issue with Xcode 8.2.1, but I believe they merely put out a lopsided mitigation in lieu of an actual fix.
With no real insight into how Xcode determines the scope of the required recompilation, it appears Xcode gets into trouble as soon as you alter the external interface of a (any) source file. This includes adding new functions, modifying existing function signatures, altering the inheritance chain and the like (which has to be 75% of the time, right!).
I have been struggling with this particular rough patch in Swift for the better part of a year and resulting frustration has even driven me to reconsider Objective-C. Folly, I know! On a more serious note, though: the current compiler/toolchain performance is a severely limiting factor on my overall coding productivity. Stuff takes longer to get done. My MacBook’s fans are ablaze all day long. And I drift off to Facebook and Twitter in between builds and struggle to pick up where I left off 😫🤕.
This is not to say that I don’t absolutely prefer Swift over Objective-C (and any other higher-level language, for that matter). I love the enthusiastic community surrounding it. The general direction the open-source project is taking the language is equally as encouraging. But its newly-fangled-ness makes the fledgling language pretty rough around the edges. Perhaps the 1.0 moniker was bestowed on it too soon? Perhaps it’s my fault for being an early adopter? Maybe. All I know is that this part of Swift still needs quite a bit of work. I just hope enough of the smart minds in the Swift community are looking as much inward, as they are forward.
SourceKitService is the memory-hungry background process which powers Xcode’s syntax highlighting and code analysis. Even though it has dramatically improved since Swift 2, its performance remains a big issue. Too often, code will be marked as erroneous or no syntax highlighting will be available at all. Despite being decoupled at the process-level, Xcode still depends strongly on SourceKitService. Autocompletion and ⌘-click navigation, for instance, are severely impacted by SourceKit bugs. A rebuild often resolves the bug, albeit terribly slowly, because of my earlier gripe…
As much as I love to bask in the glory that is Swift’s newness and road to world domination, I also need things to work, and waiting around for a computer isn’t really my idea of “working”. But I — and no doubt many others — will continue to put up with it.
Because we believe in the Swift project, right?