Observations, stories, projects, photos.

In English and Russian.

Swift single-file compilation

Nov 27, 2015, 2:11

There comes a time during the life of your Swift project when the compile times just don't cut it. There are some tweaks and knob twirling you can do to improve them, but honestly, it doesn't make that much of a difference.

I started looking around and found the deck “Swift compile time is so slow” by Masato Oshima where he claims that concatenating all the files together improved his build time sevenfold, from 6 minutes 55 seconds to a bit under a minute. “Impressive!” I thought and decided to test this approach for our project.

Now, concatenating all files to help the compiler out is not a new method, I know for certain that some game developers use it for C++ and the results are no less staggering, so this is a legitimate thing to try.

Let's get to the test results. At the time of writing our project is about 40k lines of Swift code and a dozen of external frameworks. I used the slightly modified concatenate_swift_files.sh from keychain-swift, their version disposed of the newlines we used in some of our strings so I had to edit the script to handle that. Otherwise, no changes.

The time is from tapping on Run in Xcode to the Simulator appearing.

Concatenated files: 2 minutes 8 seconds.
Normal source files (around 300 of them): 2 minutes 32 seconds.

Result: a measly 16% improvement. Not worth pursuing for our project. On top of that, the logger we use (XCGLogger) showed all debug prints originating in the concatenated file (versus a specific source file), which is logical and expected, but annoying and unhelpful.

Your comment
won’t be published

HTML will not work

Ctrl + Enter
Popular