简体   繁体   中英

Android Gradle Build not using all my M1 Pro CPU cores

Is there any way how I can setup my Android gradle project to be build using all (more) cores of my CPU?

I have MBP M1 Pro and as you can see on attached image bewow when performing Rebuild Project it is not using all my cores in the same way.

My M1 Pro has 10 CPU cores and 2 of them are low performance and 8 performance. I would like to AS use all 8 performance cores to build my project.

There is my gradle.properties setup:

org.gradle.caching=true
android.useAndroidX=true
android.enableR8.fullMode=true
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true

I was little bit playing also with org.gradle.workers.max and org.gradle.parallel.threads but I didn't see any change in CPU usage at all. But maybe I just misunderstood how it works and set incorrect values.

在此处输入图像描述

Rebuild Project stands for many Gradle tasks and a few IDE jobs like file indexing, I think your screenshot was captured in the middle stage, thus I consider the factor that impacts CPU loads balance is Gradle.

However, Gradle can not guarantee full usage of your CPU due to some restrictions:

  1. --parallel is used for tasks from different modules to run in parallel, the effect depends on " Decoupled Projects " prerequisite, you may want to check the project states / dependencies.
  2. worker is used to separate a task into several sub "works", AGP adopted it since 4.x and used it aggressively(divide tasks into tiny works), if the project has quite a lot of modules(let say >50) and resources, 8 cores maybe even slower than 4 cores due to too many workers (eg. a work can be finished in 0.1ms, but Lock Contention wastes more time). Using the latest AGP may resolve the problem, you can check the AGP version and try to reduce core numbers.
  3. This is a thread usage screenshot scanning an open-source project tivi build process by build scan , it shows the first few frames for parallelly running tasks, it's slightly better than yours I guess, but eventually CPU cores are not fully occupied. You can analyze the build using the same tool.

tivi 构建扫描

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM