当前位置:网站首页>Optimization of application startup speed
Optimization of application startup speed
2022-07-07 03:10:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
Mac OS/Android Hereunder Static Initializer
Mozillaproject Through optimization Static Initializer( initiate static , Or global constructor , Global Constructor) and Binary Layout to improve FireFox Start speed article . It is of great reference value .
In the article x86 And x86-64 Platform based , Added below Mac OS And Android Upper binary Layout .
What is? Static Initializer? In short, the overall situation C++ Object initialization .
Someone laughed and said C++ programmatic main() Before the function runs , Maybe everything is done . This is it. Static Initializer Influence . Suppose there is another layer of dependent references , It will greatly affect the startup time . The following is a demo sample program :
MyClass oneClass(0x010203); const MyClass twoClass(0x010204); attribute ((constructor)) void foo(void) { printf(“foo is running and printf is available at this point\n”); } int main(int argc, const char * argv[]) { //do something here… }
The first two objects oneClass and twoClass That is, two objects that use static initialization , and foo Function is forced into the initialization section of the program through compilation options (init segement) in , It will run when the program is initialized . The following is finally in Mac OS Layout on :
stay Android ARM ELF The following layout is shown in :
FireFox The optimization of the stay Mozillaproject Teacher's article [ link ] in , be based on Firefox 4.0b8 stay x86 And x86-64 The test data found, for example, the following average startup time :
Average startup time (ms)
Pages Read
Bytes Read
x86
3,228.76 ± 0.57%
4,787
19,607,552
x86-64
3,382.0 ± 0.51%
5,874
24,059,904
Use systemtap[ link ] You can get an access to the core library libxul.so Of access pattern:
The red dot indicates the number of pages loaded from the disk
The red line is the location in the document (seek) operation
The color patches in the background represent .rel.dyn/.rela.syn( Red )..text( Pink ),.rodata( green ),.data.rel.ro( Light green ).
Static Initializers
At the beginning, those vertical lines are Static Initializers Running time , It takes up a lot of time . The solution is to reduce static initializers. Pay special attention to those global variables 、 Static variables .
Analyzed in this way , We all have 237 individual static initializers, among 147 By cycle collection globals Introduced . After revision cycle collection The global object of is reduced to a , The whole situation has not changed much :
Average startup time (ms)
Pages Read
Bytes Read
x86
3,216.1 ± 0.59%
4,656
19,070,976
x86-64
3,488.14 ± 0.75%
5,759
23,588,864
Here are the new I/O access pattern:
I/O Although it has decreased , In fact, there are many other reading operations in static initialization It happened before , So there are other jobs to do .
Reordering objects
Another job is to lay out again binary, So that the data required by the kernel can be obtained as soon as possible . Before Taras A study found that just do something toolchain Changes on can be achieved .
Use Taras Of icegrind After optimization . The improvement became obvious :
Average startup time (ms)
Pages Read
Bytes Read
x86
2,939.18 ± 0.81%
4,129
16,912,384
x86-64
3,247.64 ± 0.68%
5,254
21,520,384
I/O pattern: Packing Relocations Last , Then we can reduce relocation paragraph . To optimize startup time . This can effectively reduce I/O, as well as dynamic relocations section, It can also reduce the package . The tools I use are here . Refer to : About adjusting ELF Optimize the startup time. The following is the final effect :
Average startup time (ms)
Pages Read
Bytes Read
x86
3,149.32 ± 0.62%
4,443
18,198,528
x86-64
3,191.58 ± 0.62%
4,733
19,386,368
I/O Pattern For example, the following : This is an obscure topic , Non Party organizations deserve in-depth study . Start with the links provided by the author . My level is limited . throw away a brick in order to get a gem , Looking forward to more in-depth elaboration . Reprint please indicate the source : http://blog.csdn.net/horkychen Refer to 1. How to Make Startup Suck Less (Also Reduce Memory Usage!) 2. Death by static initialization 3. icegrind - Valgrind Plugin for optimizing Cold Startup 4. Resolving ELF Relocation Name / Symbols 5. Static initializers 6. ELF for ARM Architecture
Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116786.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢
硬件之OC、OD、推挽解释
uniapp的表单验证
Redis入门完整教程:复制配置
The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing
知识图谱构建全流程
「小样本深度学习图像识别」最新2022综述
Le tube MOS réalise le circuit de commutation automatique de l'alimentation principale et de l'alimentation auxiliaire, et la chute de tension "zéro", courant statique 20ua
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
Babbitt | metauniverse daily must read: is IP authorization the way to break the circle of NFT? What are the difficulties? How should holder choose the cooperation platform
A complete tutorial for getting started with redis: RDB persistence
随机推荐
netperf 而网络性能测量
A complete tutorial for getting started with redis: RDB persistence
Redis入门完整教程:复制拓扑
Unity使用MaskableGraphic画一条带箭头的线
Left value, right value
左程云 递归+动态规划
A complete tutorial for getting started with redis: AOF persistence
【Socket】①Socket技术概述
Leetcode 77: combination
Form validation of uniapp
Redis入门完整教程:问题定位与优化
Left path cloud recursion + dynamic planning
How to analyze fans' interests?
掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺
Introduction to ins/gps integrated navigation type
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
首届“量子计算+金融科技应用”研讨会在京成功举办
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
Cocos2d-x Box2D物理引擎编译设置
Use of promise in ES6