Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed up Xcode Swift build times

As my project has grown over the past year, so have its build times. Over the last few months it's gone from 4 minutes to around 7 (time includes GitHub pull, unit tests, etc).

I have investigated with -Xfrontend -debug-time-function-bodies to find lines that are slow to compile, and changed that code.

I believe it's now a question of project size; 182 Swift files, ≈31K lines. 23 storyboards, 52 XIBs. This is a regular UIKit app with a handful of Cocoapods dependencies.

The bulk of the build time is spent in the "Compiling Swift source files" phase.

The build machine time I care less about than the edit-build-debug cycle, which has also been slowing.

What can be done to improve build times?

like image 472
Graham Perks Avatar asked Nov 03 '16 16:11

Graham Perks


1 Answers

Here's an article about benchmarking/speeding up compilation time - swift-profiling.

In case it goes dead here is the tldr:

xcodebuild -workspace App.xcworkspace -scheme App clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep .[0-9]ms | grep -v ^0.[0-9]ms | sort -nr > culprits.txt

You can just run that or add the following flags to your build under the other-swift-flags in build settings:

-Xfrontend -warn-long-function-bodies=100

This will show you which lines are slowing down your compile time.

like image 104
Joe Susnick Avatar answered Sep 22 '22 10:09

Joe Susnick