build: use all cores and one library variant for dev builds
- Commit
c984c274398d68c2d3677ed6059ca9688fe2b3a3- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 19:49 UTC (15 hours ago)
- Parents
0243343
Dev installs spent most of their time on work that never needed to happen at the width it ran at. Profiling scoped assembleDev builds (notes + camera + games:chess, cold, --profile) showed three systemic costs: every library compiled its release Kotlin/KSP variant for dev app builds (107s of task time in a 3-app scope, the single largest bucket), each app's mergeExtDexDev ran 12-38s with the Gradle worker cap at 2 by default (32 in ./install all), and 34 Rust modules built serially through a cargo lock of 1 with incremental compilation off. Changes: - common-conventions-app: the dev build type now prefers the library debug variant (matchingFallbacks debug, then release). Library code is identical in both variants (libraries never minify), and debug is what library unit tests already build, so assembleDev and test runs share one set of library outputs instead of compiling both. - gradle.properties: org.gradle.workers.max 2 -> 128, matching the wide, mostly independent module graph; the daemon heap stays at -Xmx8g and ./install still escalates heap for all builds. - install: all builds use --max-workers=128 (was 32), pass -Pmodernapps.cargoParallelism=16 (the pinned Rust toolchain is preinstalled on the dev box, so concurrent cargo builds cannot race a rustup install), and release-all R8 parallelism matches the repo-wide android.r8.maxWorkers=48 (was capped at 8). - RustNative: the fast (dev) cargo profile builds incrementally (CARGO_INCREMENTAL=1); release stays at 0 for byte-reproducible .so files. Profile and incremental flag are now declared task inputs, so switching profiles re-runs cargo tasks correctly. All new wiring is configuration-cache compatible (plain strings only, no Project capture). - AGENTS.md: document the new worker default. FindFamily dex: :findfamily:mergeExtDexDev passes standalone (33s wall including configuration, and the full :findfamily:assembleDev + lint run below is green), and it passed in the November install-all logs on disk. No duplicate-class or dex configuration root cause reproduces; the failure only appeared in a 69-app all build, which points at daemon memory pressure from many concurrent ~90MB external-dex merges rather than a findfamily config problem. The wider worker/heap settings above reduce that pressure per unit time but do not change dex inputs; a failing-run log would be needed to pin it further. No dependency changes were made. Measured on this dev box, which was concurrently running several other agents' Gradle builds throughout (task durations inflated up to ~3x between runs), so wall deltas are indicative, not precise: cold scoped assembleDev was 1m22s at --max-workers=128 and 1m34s at the old default of 2 before the change (contention-limited); the deterministic win is in the task graph — compileReleaseKotlin, kspReleaseKotlin, packageReleaseResources and friends no longer execute for dev builds at all (verified in the after profile and by the green lint run, which now analyzes library debug variants). Configure-on-demand was evaluated and rejected: it cut Configuring Projects from 12.4s to 7.9s on a single-module run while remaining an incubating feature with known AGP hazards. Verified: ./gradlew :findfamily:assembleDev :findfamily:lint :notes:lint :camera:lint :games:chess:lint --max-workers=128 — BUILD SUCCESSFUL (858 tasks). Configuration cache stored/reused cleanly across the changed build logic. Builds used a hardlinked clone of the shared Gradle user home because another build held the shared home's jar lock for the whole session.
Diff
AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 978b77e0d0..7bfd584c91 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -90,7 +90,7 @@ The backend (relay server for findfamily/everysync/office/voxels) lives outside ./gradlew :<module>:lint ./gradlew :<module>:checkMetadata ```-Gradle defaults to small heap (`-Xmx8g`, 2 workers). Don't raise it. New build logic must be configuration-cache compatible. New/changed UI previews: `./gradlew :<module>:metadata`.+Gradle defaults to a small daemon heap (`-Xmx8g`) with wide task parallelism (`org.gradle.workers.max=128` in `gradle.properties`; `./install all` escalates the heap, not the worker count). New build logic must be configuration-cache compatible. New/changed UI previews: `./gradlew :<module>:metadata`. Rust builds use the fast cargo profile for dev tasks and the release profile for release/ambiguous tasks, overridable with `-Pmodernapps.rustProfile=release|fast`. ## 4. Tools — use these, not raw gradle/adb
build-logic/src/main/kotlin/RustNative.kt
diff --git a/build-logic/src/main/kotlin/RustNative.kt b/build-logic/src/main/kotlin/RustNative.ktindex 168ade6479..8708c0c44f 100644--- a/build-logic/src/main/kotlin/RustNative.kt+++ b/build-logic/src/main/kotlin/RustNative.kt@@ -592,6 +592,11 @@ fun Project.rustNativeLib( inputs.property("hostTag", hostTag) inputs.property("androidApiLevel", androidApiLevel) inputs.property("targetRustflags", targetRustflags)+ // The cargo profile shapes the .so bytes and the incremental+ // setting below, and Exec environment is @Internal, so declare+ // both as inputs: switching fast/release must re-run the task.+ inputs.property("cargoProfile", profile)+ inputs.property("cargoIncremental", profile == "fast") outputs.file(destSo) val cargoHome = System.getenv("CARGO_HOME") ?: "${System.getProperty("user.home")}/.cargo"@@ -635,7 +640,10 @@ fun Project.rustNativeLib( System.getenv("SOURCE_DATE_EPOCH")?.takeIf { it.isNotBlank() }?.let { environment("SOURCE_DATE_EPOCH", it) }- environment("CARGO_INCREMENTAL", "0")+ // Release .so files must stay byte-reproducible, so release+ // builds keep incremental off. The fast (dev) profile is never+ // shipped, so it reuses incremental artifacts across edits.+ environment("CARGO_INCREMENTAL", if (profile == "fast") "1" else "0") isolatedTargetDir?.let { environment("CARGO_TARGET_DIR", it.absolutePath) } commandLine(@@ -677,7 +685,8 @@ fun Project.rustNativeLib( } // Host cdylib for JVM unit tests (testDevUnitTest / testDevUnitTest): // `cargo build --locked --target <hostTriple>` with the same profile,- // features, env (RUSTC pin, PATH, RUSTFLAGS remap, CARGO_INCREMENTAL=0),+ // features, env (RUSTC pin, PATH, RUSTFLAGS remap, profile-keyed+ // CARGO_INCREMENTAL), // toolchain lock, inputs/outputs, and caching as the per-ABI tasks above — // but WITHOUT any Android linker/NDK env (no CC/CXX/AR/SYSROOT, no // per-target LINKER/RUSTFLAGS, no 16 KB page-size link arg: that flag@@ -763,6 +772,8 @@ fun Project.rustNativeLib( // (both @Internal on Exec), so they need an explicit input property. // Deliberately NOT the NDK props: the host link must not see them. inputs.property("hostTriple", hostTriple)+ inputs.property("cargoProfile", profile)+ inputs.property("cargoIncremental", profile == "fast") outputs.file(destHostLib) val cargoHome = System.getenv("CARGO_HOME") ?: "${System.getProperty("user.home")}/.cargo"@@ -777,7 +788,7 @@ fun Project.rustNativeLib( "RUSTFLAGS", "--remap-path-prefix=$cargoHome=/cargo --remap-path-prefix=$rustSrc=/$remapLabel", )- environment("CARGO_INCREMENTAL", "0")+ environment("CARGO_INCREMENTAL", if (profile == "fast") "1" else "0") commandLine( "$cargoBin/cargo$exeExt",
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex 1e3f6fa467..29ce0ada60 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -442,7 +442,12 @@ configure<com.android.build.api.dsl.ApplicationExtension> { // render tasks are never created and `metadata` fails with "No rendered previews // found". `dev` is a developer build and never ships, so debuggable is correct here. isDebuggable = true- matchingFallbacks += listOf("release")+ // Libraries publish only debug/release variants. Prefer `debug`+ // for `dev` consumers: library code is identical in both variants+ // (libraries never minify), and `debug` is the variant library+ // unit tests already build, so assembleDev reuses those outputs+ // instead of compiling every library's release variant as well.+ matchingFallbacks += listOf("debug", "release") ndk { abiFilters.clear() abiFilters.add(ABI_ARM64)
gradle.properties
diff --git a/gradle.properties b/gradle.propertiesindex af1c14c7ad..f7b51fd02d 100644--- a/gradle.properties+++ b/gradle.properties@@ -3,10 +3,8 @@ # killing them (a kill forces a full multi-minute reconfigure on next build). # Full-repo builds (`./install all`, ~100 modules with concurrent D8 dex merge) # OOM on this heap, so ./install auto-escalates with-# -Dorg.gradle.jvmargs=<46g big-build heap> + --max-workers=32 when — and only-# when — the `all` keyword is expanded (a separate big daemon; the small one-# stays alive). Do not raise the default here — override locally in-# ~/.gradle/gradle.properties instead (same mechanism CI uses).+# -Dorg.gradle.jvmargs=<46g big-build heap> when — and only when — the `all`+# keyword is expanded (a separate big daemon; the small one stays alive). # # MaxMetaspaceSize=1024m: the previous 512m cap was killing the daemon on # release builds (R8 fullMode + lintVitalRelease + KSP + Kotlin compile all@@ -15,9 +13,12 @@ org.gradle.jvmargs=-Xmx8g -Xms512m -XX:MaxMetaspaceSize=1024m -XX:+UseG1GC -Dfile.encoding=UTF-8 kotlin.daemon.jvm.options=-Xmx1536m -# Cap parallel workers so concurrent D8/Kotlin workers fit in the default heap.-# ./install raises this for full builds.-org.gradle.workers.max=2+# Parallel task workers. The build graph is wide (~100 app modules with+# independent Kotlin/KSP/dex work), so the default uses the dev box's cores;+# scoped builds simply never queue that many tasks. The daemon heap above+# stays small — heavy compiler/dex work runs in its own daemons/workers —+# and ./install still escalates the heap for `all` builds.+org.gradle.workers.max=128 org.gradle.parallel=true org.gradle.caching=true
install
diff --git a/install b/installindex 67d2a7d056..7964a6d238 100755--- a/install+++ b/install@@ -678,8 +678,10 @@ install_apk_via_session() { GRADLE_ARGS=(--continue) gradle_args_str=" --continue" if [[ "$VARIANT_LC" == "release" && $ALL_EXPANDED -eq 1 ]]; then- GRADLE_ARGS+=(-P"android.r8.maxWorkers=8")- gradle_args_str="$gradle_args_str -Pandroid.r8.maxWorkers=8"+ # Match the repo-wide R8 process cap in gradle.properties (48 single-thread+ # deterministic processes); a lower cap here only lengthens release builds.+ GRADLE_ARGS+=(-P"android.r8.maxWorkers=48")+ gradle_args_str="$gradle_args_str -Pandroid.r8.maxWorkers=48" fi # --- Big-build heap: gradle.properties defaults to a small daemon heap sized for@@ -688,8 +690,11 @@ fi # separate big daemon; the small one stays alive for normal builds. if [[ $ALL_EXPANDED -eq 1 ]]; then GRADLE_ARGS+=(-D"org.gradle.jvmargs=-Xmx46144m -Xms4512m -XX:MaxMetaspaceSize=1024m -XX:+UseG1GC -Dfile.encoding=UTF-8")- GRADLE_ARGS+=(--max-workers=32)- gradle_args_str="$gradle_args_str -Dorg.gradle.jvmargs=<46g-big-build-heap> --max-workers=32"+ GRADLE_ARGS+=(--max-workers=128)+ # Rust crates build in parallel too (the pinned toolchain is preinstalled+ # on the dev box, so no rustup install can race — see RustNative.kt).+ GRADLE_ARGS+=(-P"modernapps.cargoParallelism=16")+ gradle_args_str="$gradle_args_str -Dorg.gradle.jvmargs=<46g-big-build-heap> --max-workers=128 -Pmodernapps.cargoParallelism=16" fi # --- versionCodeOverride: MAOS refuses to update a system package to the same