8

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.

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

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.

3 Comments

That seems helpful for really slow compiling files but since Xcode compiles many files in parallel and none of my files are high multi-second compiles I can't visually see which files take the longest as it happens too fast. Ideally there would be a way to actually see the time of each file's compiling
The swift compiler has a -j <n> option to control the # of parallel compiles. Maybe if you supply that to 1 you can watch it better.
I just tried that. It seems that swift does not go ahead so much when providing the option but still queues a couple of files for compilation. My class files are rather tiny so it just goes plop, plop, plop ,..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.