Friday, April 29, 2016

Speeding Up Slow Swift Build Times

Matt Nedrich:

Copy the above code into XCode, press “build,” and go get a coffee. Come back in 12 hours. Yes, the above dictionary literal code takes at least 12 hours to compile.

Nick O’Neill:

If you suspect that something is taking too long to compile in your Swift project, you should turn on the debug-time-function-bodies option for the compiler. In your project in Xcode, go to Build Settings and set Other Swift Flags to -Xfrontend -debug-time-function-bodies.

[…]

Now that we know type inference can be a problem here, we can investigate the problem areas, specify type information and try building again. In this case, simply defining the structure to be a Dictionary<String, AnyObject> brings our compile time for that function down to 21.6ms. Even adding the rest of the employee objects back in doesn’t meaningfully change the compile time. Problem solved! Hit the rest of the potential problem areas in your code and try adding type information to speed up the compile times for the rest of your project.

This particular case has just been improved for an upcoming Swift release.

Max Seelemann:

Good to see these issues getting discovered and also eventually fixed. Maybe Swift 3 will be prime time ready?

Marcel Weiher:

Dunno. Scala is how many years old and the compile times are still shockingly abysmal.

Previously: Swift 1.0 Performance and Compilation Times, Slow Swift Array Type Inference, Swift Type-checking Performance Case Study.

Update (2016-05-11): Tumblr:

To address this, we decided to automate monitoring of compilation performance. The goal was to create a weekly job that would compile our project with specific debug flags, process the results, and email out the slowest compilation paths.

2 Comments RSS · Twitter

[…] Speeding Up Slow Swift Build Times, Swift 1.0 Performance and Compilation Times, Slow Swift Array Type Inference, Swift Type-checking […]

[…] Previously: Speeding Up Slow Swift Build Times. […]

Leave a Comment