Author: Xu Binbin backgroundAfter a long period of business iteration, the incremental compilation of C-side engineering has seriously deteriorated. Before December 2021, the average incremental compilation of C-side was more than 3 minutes, which seriously affected the R&D efficiency and urgently needed optimization! After optimization, the incremental compilation time was reduced to about 2 minutes. analyzeXingfuli app compilation processMain time-consuming analysis
planLLVM compilation optimizationLLVM compilation processThe compilation of .m files from .o files goes through the following stages:
As you can see, a lot of work is done in the compilation process from source files to target files. If a new line of code is added to a source file, all R&D colleagues have to follow these steps again when building, which increases a lot of repetitive work and time. dolphin distributed compilation cacheThe Byte App Infra team hooks LLVM Clang. For basic compilation commands (such as oc files), they can be hashed into a unique key based on content and dependencies. After we compile the new .m, we store the corresponding .o and key on the local hard disk and remote server. When other R&D colleagues compile, they only need to download the .o file, which can greatly improve the compilation efficiency. After Xingfuli CI was connected to Dolphin, the time consumed for packaging and compilation was reduced from 600s to 240s. Resource OptimizationMain project asset compilation The main project resources will be compiled into Assets.car every time you compile. There are many images in the project stored under the resources of the main project. Each compilation will take more than 30 seconds at this step. Therefore, most of the main project image resources are migrated to the pod library, which can reduce the compilation time of the main project resources to within 5 seconds. copy pods resource Our project uses resources to reference resources. This step is to copy all pod library resources and compile and merge them into the main project's Assets.car, which takes about 40 seconds. There are two directions for optimization:
Link Optimizationld64
The static linker ld64 is responsible for analyzing the .o, .a, and .dylib files output by the compiler and other modules, and assembling executable files after parsing, redirecting, and aggregating symbols. The main workflow of ld64 is as follows: zd Zld is an optimized linker developed based on ld64. It increases the number of concurrency and uses more efficient data structures to optimize the link process. Of course, we can also participate in optimizing zld. For example, a big guy from Feishu optimized linear search through map search, reduced the time complexity of the algorithm, and optimized the time consumption of symbol resolution. Linear Search Map Search Access zld data comparisonld64 data: zld data: in conclusionData comparison: Before optimization: 3.79m After optimization: 1.91m Practical tipsResource copyWhen the project is pod installed, a resource copy script code will be generated in pods-target-resources. This script will be run during compilation. If you want to skip resource copying, just add exit 0 to the first line of resources. zld debuggingzld source code: https://github.com/michaeleisel/zld Use zld to compile the project, view the compilation log, and obtain the link command code: Delete the brackets and the contents inside, add a -v after the clang command to display the link parameters, then execute the script to generate link parameters, copy and delete the contents before -demangle, and save them to juzi.txt: -demangle -lto_library /Applications/Xcode.app/Content...... Open the zld project, adjust the compilation mode to release (debug runs too slowly, release runs fast but cannot be debugged with breakpoints), and copy the parameters of juzi.txt to arguments, then you can directly debug the link process of the project. Analysis of zld timeCopy the release executable file generated by the zld project to the desktop. Open the time profiler of instruments in Xcode and select the zld executable file on the desktop. Replace \s- in the juzi.txt parameter with \\n-, copy it to the arguments in the figure above, and then run and analyze. -demangle \ As shown in the figure, getUserVisibleName() takes a long time. Let's check the zld source code: After breakpoint or log test, I found that this method can never find the substring of ".llvm." (only as a demo test), so I tried to change it to the following code: Compile again to generate a new executable file, and test again with instruments to get the following data: Todo
|
<<: Do you know what threats your mobile devices face?
>>: iOS 15.6 official version battery life test is out, it consumes more power
According to foreign media reports recently, Borg...
If you want to achieve good results when broadcas...
As a product of the mobile era, information flow ...
[[128623]] Given the current slow development tre...
How can a new account conduct massive Qianchuan d...
Currently, the trend of online video advertising ...
Books are the ladder of human progress, but paper...
Have a pair of straight long legs It should be th...
In fact, you only need to do these three things t...
Please read this article carefully! Then you will...
A while ago, an Airdesk video by the B station UP...
In the above article "Advertising Strategy i...
The 2022 Beijing Winter Olympics and Paralympics h...
Google is very dissatisfied with the current situ...
On November 1st, Skyworth iQiyi Ultra HD Box was ...