UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How to cut Swift compile times by half

It’s easier than you think with this one weird trick…

Paul Hudson       @twostraws

Every Swift developer knows that Swift code compile times are best measured in ice ages, and historically a number of candidates have been put forward as possible culprits: slow type inference checking, string interpolation, and a lack of headers.

However, despite the community’s best efforts we’ve only ever been able to get Swift compile times down by 20% or so, and that’s even after removing all the culprits above. That left us wondering: just what is taking so long?

At long last, we can reveal not only what causes such slow Swift compile times, but provide a quick fix that will literally cut your Swift compile times by half if not more.

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Swift meets the blockchain

The original implementation of Swift was designed to be a simple replacement of Objective-C, but shortly after the first public release of Swift a secret front-end flag was inserted.

On the surface this flag was supposed to be there to help make Objective-C tests work better, but the reality was that Apple had taken the initial step towards becoming the world’s first trillion dollar company: Apple had created a fork of Bitcoin called SwiftCoin.

That in itself wasn’t unusual: lots of companies try to harness blockchain technology to deliver onboarding synergies, circle the bandwidth paradigm shifts, and ideate agile data islands.

But Apple had a unique approach: they knew developers were deeply envious of language features such as generics, operator overloading, and first-class functions, so they crafted a plan to introduce a new language to desperate developers – a language that would also secretly mine SwiftCoin while pretending to compile.

Responding to the news that SwiftCoin’s existence had leaked, Swift project lead Ed Kermenek issued an official statement from his personal aircraft carrier somewhere in the Pacific: “Hahahaha – and you really thought type inference could be that slow? I thought the plan would fail early when some folks realized compiling was slower than Objective-C, but then Kris [Latener; original creator of Swift] had the idea of making so many language changes every year that folks would be too distracted to investigate.”

It’s hard to tell how many Apple engineers benefited from the scheme, but I managed to track down Jay Gorff – one of the lead engineers on the Swift project. I found him in a mountain fortress in Aspen, Colorado, where he was burning piles of $100 dollar notes on an open fire. “It’s all true,” he said. “We literally have so much money now that I’m out of space – I’m going to have to buy my dogs bigger ski chalets just to have somewhere to put it all.”

Fortunately for all of us, the newly released Xcode 9.3 comes with an option to disable SwiftCoin mining entirely. Doing so immediately halves all Swift compilation time, and will dramatically lower your household energy bills.

To try it for yourself, simply run this command from the terminal app: defaults write org.swift.dt.compiler MineSwiftCoin -bool NO – make sure you restart Xcode afterwards, and you should be done.

If all developers upgrade to Xcode 9.3 and disable SwiftCoin mining, experts have estimated energy savings could reach up to 1.21 gigawatts – energy that could be far better used bikeshedding Swift Evolution proposals on the Swift Forums.

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 3.7/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.