Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track down slow compiling Swift code?

Xcode has added a great feature to see your application compile in real time but how can you see compile durations for individual classes and then further see what code is causing the slow compile times?

This is helpful but only gets part way there.

like image 251
Shizam Avatar asked Mar 19 '15 00:03

Shizam


3 Answers

Use xctool. When you compile your project on the command line it will emit the time taken to compile each file to the console. e.g:

✓ Compile MySwiftFile.swift (12067 ms)

Additionally, for Swift 1.2 at least there is a flag debug-time-function which can be passed to the Swift compiler to show you problematic functions.

Further discussion here

like image 181
NSTJ Avatar answered Oct 19 '22 05:10

NSTJ


Open the Report navigator (Balloon icon left pane). When you build click the top most line with the build hammer and you see the compilation progress for each compiled file.

like image 44
qwerty_so Avatar answered Oct 19 '22 04:10

qwerty_so


Swift now includes a function-by-function compiler profiler. You can enable it with the compiler flag -Xfrontend -debug-time-function-bodies.

Run a clean rebuild and use the grep command from this post to get a reverse-sorted list of compile time by function.

This was hugely helpful for me - I trimmed maybe 15 seconds off my build time by tuning the slowest-to-compile functions.

like image 34
Bill Avatar answered Oct 19 '22 05:10

Bill