I am currently looking at optimizing the compilation time of my project.
Although I knew something there called optimization of the entire module (for short WMO ), but I am afraid to check this in the build settings, since I have not delved into it yet.
As I understand:
WMO should lead to faster code execution, but slightly increase compilation time, because it compiles the whole module files as a whole, and does not compile each file separately in parallel, according to this official Swift blog on optimizing the entire module .
Therefore, it is recommended to set the Swift optimization level as follows:
- To configure debugging, set
None [-Onone] - To configure the release, set the value to
Fast, Whole Module Optimization [-O -whole-module-Optimization] as it is not so important to have better compilation time for periodic release builds.
However, when looking for tips on how to reduce compilation time for debugging configuration, I found the following user settings:
SWIFT_WHOLE_MODULE_OPTIMIZATION = YES for debuggingSWIFT_WHOLE_MODULE_OPTIMIZATION = NO for release
These settings reduced my Debug compilation time by almost half.
Since I'm new to the Swift compiler and user preferences, I tried to find the official documentation for SWIFT_WHOLE_MODULE_OPTIMIZATION but what is confusing is that there is no documentation on the network.
People just say that this reduces compilation time, but no further explanation, or they conflict with the Swift optimization level mentioned above.
As far as I understand, these settings installed on YES should increase compilation time, since this allows the use of WMO . Therefore, I think I misunderstood WMO .
Questions:
What is the difference between the Swift Optimization Level and SWIFT_WHOLE_MODULE_OPTIMIZATION ?
Why SWIFT_WHOLE_MODULE_OPTIMIZATION reduce compilation time?
Thanks!
source share