Shizam
Shizam

Reputation: 9672

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.

Upvotes: 8

Views: 1634

Answers (3)

Bill
Bill

Reputation: 45408

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.

Upvotes: 3

NSTJ
NSTJ

Reputation: 3888

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

Upvotes: 6

qwerty_so
qwerty_so

Reputation: 36295

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.

Upvotes: 1

Related Questions