Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 22.214.171.124 release ready!
Updated 29 April 2022
Here is again an interesting article that attracts the developer’s attention to how the compiler uses Whole module optimization for the Swift code.
This optimization is related to the compiler that we use for Swift development.
So without any delay let’s start diving into the article.
Here is one common answer to why we need it.
Optimizing the modules inside the project for better performance is the main reason behind the optimization.
For instance, when we create the final version of the build by combining all the files together this technique evaluates the whole build.
Using compiler flag -wmo we can enable the whole-module optimization.
The swift compiler compiles each file in the module separately, which is automatically done by the compiler behind the scenes.
The compiler optimizes the code and then generates the machine code and then creates an object file. Finally, the linker connects all the object files and creates an executable file.
Here is a simple example.
When the compiler is optimizing the SomeViewController.swift it just knows the existence of the callValue function and is not aware of its implementation.
When the compiler is optimizing the HelperClass.swift it does not know the particular type of the caller.
The compiler only generates the generic version which is much slower when the type is specified.
By using the whole module optimization technique the compiler optimizes all files of a module as a whole.
The compiler checks the implementation of all functions in the module, then the compiler specializes the generic functions to a specified type and creates a new version of the function.
So the compiler changes the function inside our HelperClass.swift file for the specialized type.
Whole module_optimization eliminates the unused non-public functions from the code. This makes the build much lighter and increases the performance.
After completing the whole module_optimization the compiler splits the modules into multiple parts, and with the help of LLVM, multiple threads are created for each part.
The compiler does not process those threads which have not changed during the development.
This saves the recompilation time for the preprocessed threads.
We hope you would like the overview of the whole module optimization.
For more detailed information please check swift documentation here
To read my other blogs please click here
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.