Mobile APP quality optimization framework - Booster

Thermal paper REVIEW |   Click on the title to read

Under Internet winter, the programmer how to break through to enhance their own?

Android technology selection

"37-year-old, 500,000 annual salary, the night was cut": Pseudo work, destroyed many Chinese youth

Author: booster (project addresses see text at the end)
link: https: //juejin.im/post/5cea22ebf265da1bb564d4d7
Brief introduction

Booster is a mobile application designed specifically for ease of use, lightweight and scalable quality optimization framework, which aims mainly to solve the complexity and improve the APP brings performance, reliability, package size and other issues.

Why is the Booster?

Quality Optimization is a problem for all application developers have faced for DAU tens of millions APP, the ten thousandth of the rate would mean the collapse of thousands of users are affected, for the long-line of the driver, the driver stability of APP related to the driver's safety and income, so should not be underestimated.

With the rapid development of business, business complexity and improve, we began to think about:

  • How to ensure the continued quality of APP?

  • After the collapse of APP, how to quickly locate the problem belongs to the line of business?

  • Can you identify potential quality issues before on-line in advance?

  • APP can be no intrusion of global quality optimization without the need to push each line of business?

Based on these considerations, Booster emerged after more than one year continuously polished, Booster success. Due to the current open source project based on static analysis of only a handful in quality optimization, coupled with quality optimization for APP developers, high threshold, so we chose to Booster open, hope that more developers and users benefit from .

Functions and Features

Dynamically loaded modules

To support the need to optimize differentiation, Booster enables dynamic loading of modules, in order to select without the use of a developer arranged in the specified module, see: Booster-Task-All, All-Booster-Transform.

Third-party libraries injection

Booster making process optimization, you may need to inject some specific classes or libraries, in order to solve the problem injection dependency management classes, Booster provides VariantProcessor SPI allows developers to easily expand, please refer to: ThreadVariantProcessor.kt # L12

Performance Testing

Caton rate APP is an important indicator when measuring applications running performance, in order to identify potential Caton problem in advance, Booster achieve the performance detected by static analysis, and generate visual reports to help develop the problem in locating, following figure It shows:

640?wx_fmt=other

The principle is that by analyzing all the class files, build a global Call Graph, and then find out (related methods Application, the four major components, View, Widget, etc.) link in the main thread calls from the Call Graph, and then in these links and then outputs the report in units of categories.

See: Booster-the Transform-lint.

Multi-threaded optimization

Numerous lines of business APP common thread overload problem, and thread management has been one of the developers of the most troublesome problem, although you can go to avoid such problems by setting strict code standards occur, but for complex organizational structures to manufacturers say, a huge cost to implement, and for third-party SDK, the code specification is bloated. In order to completely solve this problem, Booster bytecode by modifying the thread pool to achieve global optimization during compilation, and the thread is to be renamed.

The following sample code:

Rename thread results as shown below:

640?wx_fmt=other

See: Booster-the Transform-the Thread

SharedPreferences optimization

For Android developers, SharedPreferences almost everywhere, and modified in the main thread SharedPreferences will lead Caton even ANR, in order to completely solve this problem, Booster for APP in the global replacement instructions.

详见:booster-transform-shared-preferences。

Constant Field Delete

Whether it is resource index, or other constant field, after the compilation is completed, the value does not exist (except for reflection), therefore, the resource index field instruction Booster will replace constant access instruction, the other constant field is removed from the class , can improve run-time performance on the one hand, on the other hand, can reduce the package volume of the resource index (R) seemingly trivial, in fact, occupy a lot of space, drops to the owner, for example, the resource index related classes there are thousands, after constant field deleted, reduced by about 1MB.

详见:booster-transform-shrink。

Toast Bug fix

In order to solve the bug exists in the Android 7.1: 30150688, Booster of APP in Toast.show () method call instruction global replacement.

See: Booster-the Transform-Toast.

Resource Compression

APP package volume is also a very important indicator, the APP installation, picture resources accounted for a large proportion, usually the case, the picture quality is reduced by 10% -20% will not affect the visual effects, therefore, Booster lossy compression to reduce the size of the image, and the image size is smaller, faster loading, occupies the less memory.
Booster offers two compression schemes:

  • pngquant lossy compression (requires its own command-line tool pngquant)

  • cwebp lossy compression (already built)

Two programs have advantages and disadvantages, compatibility issues pngquant program does not exist, but the compression rate is slightly lower than WebP, and WebP version compatibility issues exist in the system, the whole, lossy compression effect is very significant, with drops owners an example, APP package volume is reduced by about 10 MB.

另外,像 Android Support Library 中包含有大量的图片资源,而且支持多种屏幕尺寸,对于 APP 而言,相同的图片资源,保留最大尺寸的即可。以 Android Support Library 为例,去冗余后,APP 包体积减小了 1MB 左右。

详见:booster-task-compression。

WebView 预加载

为了解决 WebView  初始化导致的卡顿问题,Booster 通过注入指令的方式,在主线程空闲时提前加载 WebView。

除上以上特性外,Booster 还提供了一些辅助开发的功能,如:检查依赖项中是否包含 SNAPSHOT 版本等等。

快速入门

在 buildscript 的 classpath 中引入 Booster 插件,然后启用该插件:

 
  

buildscript {
    ext.booster_version = '0.4.3'
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "com.didiglobal.booster:booster-gradle-plugin:$booster_version"
        classpath "com.didiglobal.booster:booster-task-all:$booster_version"
        classpath "com.didiglobal.booster:booster-transform-all:$booster_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.didiglobal.booster'

然后通过执行 assemble task 来构建一个优化过的应用包:

 
  

$ ./gradlew assembleRelease

构建完成后,在 build/reports/ 目录下会生成相应的报告:

 
  

build/reports/
├── booster-task-compression
│   └── release
│       └── report.txt
├── booster-transform-lint
│   └── release
│       ├── com
│       └── org
├── booster-transform-shared-preferences
│   └── release
│       └── report.txt
├── booster-transform-shrink
│   └── release
│       └── report.txt
├── booster-transform-thread
│   └── release
│       └── report.txt
└── booster-transform-toast
    └── release
        └── report.txt

项目地址:https://github.com/didi/booster

更多学习和讨论,欢迎加入我们的知识星球,这里有1000+小伙伴,让你的学习不寂寞~·

94年12月,我们小分队在滇西北找矿。小分队一共8人,其中4名警战士每人配备一支冲锋枪。一天,出发前,一位纳西族老乡搭我们的车去维西。那天路上积雪很大,雪下的路面坑洼不平,车子行驶一段就会被雪坞住。我们不得不经常下来推车。就在我们又一次下车推车的时候,一群褐黄色的东西慢慢向我们靠近。我们正惊疑、猜测时,纳西族老乡急喊:“快、快赶紧上车,是一群狼。”司机小王赶紧发动车,加大油门……但是很不幸,车轮只是在原地空转,根本无法前进。这时狼群已靠近汽车……大家看得清清楚楚——8只狼,个个都象小牛犊似的,肚子吊得老高。战士小吴抄起冲锋枪,纳西族老乡一手夺下小吴的抢。比较沉着地高声道:“不能开枪,枪一响,它们或钻到车底下或钻进树林,狼群会把车胎咬坏,把我们围起来,然后狼会嚎叫召集来更多的狼和我们拼命。”他接着说:“狼饿疯了,它们是在找吃的,车上可有吃的?”我们几乎同声回答:“有。”“那就扔下去给它们吃。”老乡像是下达命令。从来没有经历过这样的事,当时脑子里一片空白,除了紧张,大脑似乎已经不会思考问题。听老乡这样说,我们毫不犹豫,七手八脚把从丽江买的腊肉、火腿还有十分珍贵的鹿子干巴往下丢了一部分。狼群眼都红了,兴奋地大吼着扑向食物,大口的撕咬吞咽着,刚丢下去的东西一眨眼就被吃光了。老乡继续命令道:“再丢下去一些!”第二批大约50斤肉品又飞出了后车门,也就一袋烟的工夫,又被8只狼分食的干干净净。吃完后8只狼整齐地坐下,盯着后车门。这时,我们几人各个屏气息声,紧张的手心里都是冷汗,甚至能够清晰的听到自己心跳的声音……我们不知道能有什么办法令我们从狼群中突围出去。看到这样的情形,老乡又发话道:“还有吗?一点不留地丢下,想保命就别心疼这些东西了!”此时,除了紧张、害怕还有羞愤……!作为战士,我们是有责任保护好这些物资的,哪怕牺牲自己。但是现实情况是我们的车被坞到雪地里出不来,只能被困在车里。我们的子弹是极有限的,一旦有狼群被召唤来,我们会更加束手无策。我们几人相互看了一眼,迟疑片刻,谁也没有说什么,忍痛将车上所有的肉品,还有十几包饼干全都甩下车去!8只狼又是一顿大嚼。吃完了肉,它们还试探性的嗅了嗅那十几包饼干,但没有吃。这时我清楚地看到狼的肚子已经滚圆,先前暴戾凶恶的目光变得温顺。其中一只狼围着汽车转了两圈,其余7只狼没动。片刻,那只狼带着狼群朝树林钻去......不可思议的事情发生了……不一会儿,8只狼钻出松林,嘴里叼着树枝,分别放到汽车两个后轮下面。我们简直不敢相信自己的眼睛……这些狼的意思是想用树枝帮我们垫起轮胎,让我们的车开出雪窝。我激动地大笑起来……哈……哈……刚笑了两声,另外一个战士忙用手捂住了我的嘴,他怕这突兀的笑声惊毛了狼。接着,8只狼一齐钻到车底,但见汽车两侧积雪飞扬。我眼里滚动着泪花,大呼小王:“狼帮我们扒雪呢,赶快发动车,”车启动了,但是没走两步,又打滑了。狼再次重复刚才的动作:“先往车轮下垫树枝,然后扒雪……”。就这样,每重复一次,汽车就前进一段,大约重复了十来次。最后一次,汽车顺利地向前行了一里多地,接近了山顶。再向前就是下坡路了。这时,8只狼在车后一字排开坐着,其中一只比其他7只狼稍稍向前。老乡说:“靠前面的那只是头狼,主意都是他出的。”我们激动极了,一起给狼鼓掌,并用力地向它们挥手致意。但是这8只可爱的狼对我们的举动并没有什么反应,只是定定地望了望我们,然后,头狼在前,其余随后,缓缓朝山上走去,消失在松林中......看完不忍思考:连凶猛的狼都懂得报恩,我们是否应该反思自身?类,我们是不是应当让这个世界充满爱?。小分队一共8人,其中4名警战士每人配备一支冲锋枪。一天,出发前,一位纳西族老乡搭我们的车去维西。那天路上积雪很大,雪下的路面坑洼不平,车子行驶一段就会被雪坞住。我们不得不经常下来推车。就在我们又一次下车推车的时候,一群褐黄色的东西慢慢向我们靠近。我们正惊疑、猜测时,纳西族老乡急喊:“快、快赶紧上车,是一群狼。”司机小王赶紧发动车,加大油门……但是很不幸,车轮只是在原地空转,根本无法前进。这时狼群已靠近汽车……大家看得清清楚楚——8只狼,个个都象小牛犊似的,肚子吊得老高。战士小吴抄起冲锋枪,纳西族老乡一手夺下小吴的抢。比较沉着地高声道:“不能开枪,枪一响,它们或钻到车底下或钻进树林,狼群会把车胎咬坏,把我们围起来,然后狼会嚎叫召集来更多的狼和我们拼命。”他接着说:“狼饿疯了,它们是在找吃的,车上可有吃的?”我们几乎同声回答:“有。”“那就扔下去给它们吃。”老乡像是下达命令。从来没有经历过这样的事,当时脑子里一片空白,除了紧张,大脑似乎已经不会思考问题。听老乡这样说,我们毫不犹豫,七手八脚把从丽江买的腊肉、火腿还有十分珍贵的鹿子干巴往下丢了一部分。狼群眼都红了,兴奋地大吼着扑向食物,大口的撕咬吞咽着,刚丢下去的东西一眨眼就被吃光了。老乡继续命令道:“再丢下去一些!”第二批大约50斤肉品又飞出了后车门,也就一袋烟的工夫,又被8只狼分食的干干净净。吃完后8只狼整齐地坐下,盯着后车门。这时,我们几人各个屏气息声,紧张的手心里都是冷汗,甚至能够清晰的听到自己心跳的声音……我们不知道能有什么办法令我们从狼群中突围出去。看到这样的情形,老乡又发话道:“还有吗?一点不留地丢下,想保命就别心疼这些东西了!”此时,除了紧张、害怕还有羞愤……!作为战士,我们是有责任保护好这些物资的,哪怕牺牲自己。但是现实情况是我们的车被坞到雪地里出不来,只能被困在车里。我们的子弹是极有限的,一旦有狼群被召唤来,我们会更加束手无策。我们几人相互看了一眼,迟疑片刻,谁也没有说什么,忍痛将车上所有的肉品,还有十几包饼干全都甩下车去!8只狼又是一顿大嚼。吃完了肉,它们还试探性的嗅了嗅那十几包饼干,但没有吃。这时我清楚地看到狼的肚子已经滚圆,先前暴戾凶恶的目光变得温顺。其中一只狼围着汽车转了两圈,其余7只狼没动。片刻,那只狼带着狼群朝树林钻去......不可思议的事情发生了……不一会儿,8只狼钻出松林,嘴里叼着树枝,分别放到汽车两个后轮下面。我们简直不敢相信自己的眼睛……这些狼的意思是想用树枝帮我们垫起轮胎,让我们的车开出雪窝。我激动地大笑起来……哈……哈……刚笑了两声,另外一个战士忙用手捂住了我的嘴,他怕这突兀的笑声惊毛了狼。接着,8只狼一齐钻到车底,但见汽车两侧积雪飞扬。我眼里滚动着泪花,大呼小王:“狼帮我们扒雪呢,赶快发动车,”车启动了,但是没走两步,又打滑了。狼再次重复刚才的动作:“先往车轮下垫树枝,然后扒雪……”。就这样,每重复一次,汽车就前进一段,大约重复了十来次。最后一次,汽车顺利地向前行了一里多地,接近了山顶。再向前就是下坡路了。这时,8只狼在车后一字排开坐着,其中一只比其他7只狼稍稍向前。老乡说:“靠前面的那只是头狼,主意都是他出的。”我们激动极了,一起给狼鼓掌,并用力地向它们挥手致意。但是这8只可爱的狼对我们的举动并没有什么反应,只是定定地望了望我们,然后,头狼在前,其余随后,缓缓朝山上走去,消失在松林中......看完不忍思考:连凶猛的狼都懂得报恩,我们是否应该反思自身?自诩为“万物灵长”的人类,我们是不是应当让这个世界充满爱?

After reading this article harvest? Please forward to sharing more people


Our knowledge of the opening of the third planet, has reached 1100 people, and be able to do three in a row has been very easy, there are a lot of old customers renewed, the current renewal rate of 50%, indicating that the people of our knowledge the planet is still very accepted, welcome to join us as soon as possible knowledge of the planet , the planet more information, see:

Welcome to Java and Android architecture community

How advanced Java for Android and become an architect?

He says two things

640?wx_fmt=jpeg

Click on the micro-channel scanning or receive Fanger Wei code of Android \ Python's \ AI \ of Java and other senior Advanced Resources

Click below to learn more information , "read the original  " Get

640?wx_fmt=gif

Thank you, boss, good-looking point ↓

Guess you like

Origin blog.csdn.net/xJ032w2j4cCjhOW8s8/article/details/91470846