How to speed up slow Swift compile times

Swift code compiling slowly? Here’s how to find out what’s causing it.

Under Build Settings, add “-Xfrontend” “-debug-time-function-bodies” to your Other Swift Compiler flags.

Open terminal.

List files sorted by slowest compile time:

$ xcodebuild -workspace MyProject.xcworkspace -scheme MyProject clean build | grep [1-9].[0-9]ms | sort -n

List functions grouped by slowest compile time:

$ xcodebuild -workspace MyProject.xcworkspace -scheme MyProject clean build | grep [1-9].[0-9]ms | awk '{arr[$2]+=$1} END {for (i in arr) {print arr[i], i}}' | sort -n

Print total compile time:

$ xcodebuild -workspace MyProject.xcworkspace -scheme MyProject clean build | grep [1-9].[0-9]ms | sort -n | awk '{SUM+=$1}END{print SUM}'

More here: http://irace.me/swift-profiling/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s