Drops open Booster: Mobile APP quality optimization framework

This article from the technical team drops terminal

14847428-bf03aec7760fbe55

Project Address: https://github.com/didi/booster

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.

This paper to introduce the next Booster function and realization of ideas, regarded as an Introduction, hoping to help you:

14847428-c2e801c993c3a778

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:

  1. How to ensure the continued quality of APP?

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

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

  4. 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, booster-transform-all.

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:

14847428-be85868aff36ba05

The principle is that by analyzing all the class files, build a global Call Graph , and then from the Call Graph identify the link called in the main thread ( Applicationthe four major components View, Widgetand other related methods), then these link units in each class the output report.

See: booster-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:

class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setContentView(R.layout.activity_main)        getSharedPreferences("demo", MODE_PRIVATE).edit().commit()    }    override fun onStart() {        super.onStart()        Thread({            while (true) {                Thread.sleep(5)            }        }, "#Booster").start()    }    override fun onResume() {        super.onResume()        HandlerThread("Booster").start()    }}

Rename thread results as shown below:

14847428-01d627127b12abf4

See: booster-transform-thread.

SharedPreferences optimization

For Android developers, SharedPreferencesalmost everywhere, but in the main thread modification SharedPreferencescan lead to 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 to bit owners , 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 in Android 7.1 in the presence of: 30150688, Booster for APP in the Toast.show()call instruction method global replacement.

See: booster-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:

  1. pngquant lossy compression (to install their own pngquant command-line tool)

  2. cwebp lossy compression (already built)

Two programs have advantages and disadvantages, pngquantthe program no compatibility issues, 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 to drops owners as an example, APP package volume is reduced by about 10 MB.

In addition, like Android Support Library contains a large number of image resources, and support a variety of screen sizes, for the APP, the same image resources, it can retain the maximum size. In Android Support Library , for example, the redundancy elimination, the APP packet volume is reduced by about 1MB.

See: booster-task-compression.

WebView preload

In order to solve WebViewCaton initialization problems caused, Booster injection by way of instruction, when the main thread is idle to load in advance WebView.

In addition to the above characteristics outside, Booster also provides some auxiliary functions of development, such as: whether to include dependency checking SNAPSHOT version and so on.

Getting Started

In the buildscriptintroduction Booster plugin classpath, and then enable the plug-in:

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'

Then performing assembleto build an optimized application package task:

$ ./gradlew assembleRelease

After the build is complete, the build/reports/directory will generate the report:

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

Finally About the Author

Author In Shenzhen, 13 in turn Android java development, small factories stayed in, also visited Huawei, OPPO, etc. into Tencent last April until now. Other manufacturers also had to be interviewed a lot of people. Android engineers know that most middle-class, want to upgrade their skills, often find their own way to grow, to learn the effect of inefficient fragmentation of long and helpless.

I took a year to put together a T4 level Tencent Android architect full set of learning materials , particularly suitable for 3 - 5 years experience of more than a small partner to enhance the in-depth study.

Including Tencent, and byte beating, Huawei, millet, and other first-tier Internet companies mainstream architecture technology. If you have a need, despite the good away. As you can learn how much really can only see your own

A full set of advanced system architecture video; seven mainstream technology module

Display portion ; Java source code kernel video + + Notes

14847428-b98f7a2abe92a9c2.png

Free Share

Click for information on the document;

"Tencent T4 level technical architect cerebral FIG Android + full video" link.juejin.im

Why are free to share?

I do not have a lot of friends because of the threshold of developers miss this high-level architecture data, missed to enhance the possible architect. Thousands and thousands of domestic programmers, most of the status quo warm boiled frog, relying on overtime every day, holding outsiders thought pretty good salary.

Remember their technical level is our core competence, please do not give the young and able to work overtime as the capital.

Reproduced in: https: //www.jianshu.com/p/9873f382601f

Guess you like

Origin blog.csdn.net/weixin_34198762/article/details/91216647
Recommended