7

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.

Community
  • 1
  • 1
Shizam
  • 9,627
  • 8
  • 51
  • 82

3 Answers3

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

Community
  • 1
  • 1
NSTJ
  • 3,858
  • 2
  • 27
  • 34
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.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 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 – Shizam Mar 19 '15 at 16:11
  • The swift compiler has a `-j ` option to control the # of parallel compiles. Maybe if you supply that to 1 you can watch it better. – qwerty_so Mar 19 '15 at 19:40
  • 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 ,.. – qwerty_so Mar 19 '15 at 19:46
1

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.

Bill
  • 44,502
  • 24
  • 122
  • 213