
Reduce swift app build time and code optimization
Reduce swift app build time and code optimization
While working on a large product-based application, I realized that the app was taking too much time to build. My next goal was to reduce build time and optimize the code.
In my case, the initial aim was to identify and fix the most time-consuming areas using Build Time Analyzer for Xcode.
How to set up Build Time Analyzer for Xcode
Go to this link and download or clone the project. After this, you just need to open that project into Xcode and Press CMD + B to build the project.
Once the build is done you need to Archive the build.
Archive the build
After completion of the archive, you need to export this build and select the option Export as a macOS App.
Now save it in your location open that folder and install the application. Thats it.
Now big question here is how this app will identify our app and generate an analysis report.
Follow this instruction
We are to add a custom flag on our application.
1. Select your target and go to Build Settings -> Swift Compiler -> Other Swift Flags and add this code -Xfrontend -debug-time-function-bodies.
Ensure that the below flags are added to your target’s Build Settings.
2. Clean your project (CMD + Shift +K)
3. Build your project (CMD + B) and wait for it to complete.
After build completion go to Build Time Analyzer App and click on your app.
Now you can see the report generated by the Build Time Analyzer App and analyze which function and code is taking more time. Based on that you can optimize your code and reduce the build time.
Make sure you are following the correct swift syntax format. Also, you need to use time-consuming functions.
Example:-
Use guard instant of if-else statement.
Thanks
Hope you learned something new today.
Enjoy!!
If you enjoyed reading this post, please share and recommend it so others can find it too ??????!!!!
You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn.
If you have any comments, questions, or recommendations, feel free to post them in the comment section below!