I'm inspecting what happens in our project during compile time. For incremental builds, under the stage of "Compile Swift source files", I do see in the build timeline that only the files that were changed are re-compiled. However, there's also a very long stage called "Emit Swift Module" ("EmitSwiftModule normal arm64"), that takes very long, and also relates to file that were not touched.
Can you please shed light on:
- What is this stage?
- Why does it recompile everything every time?
- Is there a way to avoid recompiling everything every time? Or reduce it in any way? Such as splitting the code to avoid re-compilation
If it matters, we have a mixture of objc and Swift, but it's mostly Swift.
Thank you!
1 Like
Answering my own question after talking to Apple engineers about it in WWDC lab session -
The emit swift module phase (I see it's now named "Emitting module for ") is responsible for creating a swift binary for your module. Currently, there's no option for running it selectively, meaning it does indeed run fully for every change you make for your module.
So if you have a lot of Swift code, or anticipate your code growing in such way that you will have many Swift files under one target in the future, you can split your code into smaller modules. If those modules makes sense semantically, meaning in most tasks you are unlikely to change files from more than one module, this will probably save you a lot of compilation time.