How to best modularize an Xcode project to speed up building

Viewed 1515

I work in a team on an iOS project that has grown to enormous size in terms of Swift code.

It takes about 10 minutes to build the project from the clean state and, most scrutinizing, 30 seconds to build and run the project after changing anything in the code, even if that code pertains to a single line in a private method in Swift file symbols from which are not used anywhere else.

We've tried lots of thing to improve build times, including techniques from this nice resource https://github.com/fastred/Optimizing-Swift-Build-Times Nothing helped, you still need to wait the whole 30 seconds after changing every minor thing to see it in the app.

We use Xcode 10, the "New build system" with the compilation mode set to Incremental. If I build the project via Perform Action > Build With Timing Summary, the longest phase is "Swift code compilation" which is nothing new. We suspect that Xcode tries to follow conservative compilation decision making and rebuilds every Swift file that could potentially have any connection to the modified Swift code. And it seems that Xcode is wrong most of the time and does redundant work.

I kinda miss Objective-C days when the compiler would look at the all import/include statements and only rebuild explicitly declared dependencies, which meant blazing fast build times.

So I now think that maybe we could break our project into modules and ubiquitously use import in Swift to tell the compiler what Swift files depend on what other Swift files.

Is there a good and perhaps automated way to modularize a big project into many small components to speed up regular lets-try-how-it-works builds?

2 Answers

I might be late to the party here, but we are using this tool: https://github.com/yonaskolb/XcodeGen/

Not only did it allow us to easily split the project into modules, it completely eliminated conflicts in the project file, because it doesn't need to be added to the repository any more.

Related