I learned the open class of Kuaishou, hereby record

How to improve Android compilation speed

background

Too many lines of code, too many moudle numbers in traditional means, such as

  • Parallel
  • Compiler daemon
  • ABI componentization
  • Builed Cache
  • incremental build
  • Compile avoidance

How can we improve when we have already done our best

Special means

The whole compilation and construction process is divided into two stages. The code is compiled first, and then tramsfrom is used for construction. From these two aspects, the ultimate compilation is made

The compile phase

ABI

The ABI(Application Binary Interface) is a set of rules for how applications run on the platform. The purpose of the ABI is to tell compilers and linkers how to compile and link programs. If we know the rules, we can customize the rules. The customization rules are as follows

1 Syntax level

public method change
public filed change
public class added
Copy the code

2 File Level

Code Source file change

Resource Source file change

3 Environment Level

Dependency change

Gradle properties change

Incremental compilation occurs when these functions or files change

task.doFirst {
    if(task.state.upToDate) {
       return@doFirst
    }
    val changed = runBlocking {
       diff change
    }
    if(! changed && !task.state.upToDate) 
       throw StopExecutionException()
}
Copy the code

Dynamic AAR dependency

The Transform optimization

Transform is used to perform operations on class files, such as Progrard, APT, asm, before converting a class file to a dex file. Each Transform task is sequential, that is, jar is converted to class and jar is converted again. Can we reduce the repetition in this process?

For example, open multiple threads to parallel execution, but too many threads will increase the burden of CPU, can be through Kotlin’s coroutine +NIO parallel I/O operation, because the coroutine will reduce the performance loss caused by switching between kernel state and user state, I/O operation to release CPU, enhance CPU computing performance utilization, reduce the performance loss caused by thread locking mechanism

That’s it. What else can you do to improve your Android build speed?

Physical means – plus configuration

Push the code to the cloud host (for example, configure 64GB of memory), then mount it to the compiled cluster using WorkSpace, and install the compiled APK on the phone

How to customize the business side’s ARR-China implementation

Product matrix in the company, product B wants to realize the tool generation function of product A, how to achieve high customization? Analysis using MapFiles+ bytecode

How to Monitor the OOM