We had problems with very slow compilation times on our rather large projects. Based on this wonderful article: https://thatthinginswift.com/debug-long-compile-times-swift/ I set my quick compiler flags:
-Xfrontend -debug-time-function-bodies
and started debugging. I found out that for every file that was compiled (> 200), it will also compile with it several seemingly unrelated files.
After further debugging, it seems that if you add any extension like this to the class or structure:
extension MasterViewController {
func someFunc(){
}
}
the MasterViewController class will be compiled with any unrelated file for your purpose.
In my small project project, there is also a DetailViewController that pops out of the MasterViewController. Since MasterViewController refers to it, it must also be recompiled with it. Each time for each file.
In this small project, compilation time is still fast, but you can see how it can become very slow in a large project where extensions are used in several classes. In our project, more than half of the source files are recompiled every time.
To test the problem, download the CompilerTest project here https://1drv.ms/u/s!Av6oIon-UawdxmUtmDCNWF_zOcjn
Then create a project and go to the latest version in the report navigator. After the extension TestFile.swift, you will see that MasterViewController has also been compiled, although it is not mentioned at all in the file.
MasterViewController.swift, . . , TestFile , .
, , .