install: batch device queries and parallelise session installs
- Commit
555ebda19b26f4a2ed7b9eeb68a797f04d17519b- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 21:59 UTC (10 hours ago)
- Parents
8ccc449
Two serial adb phases dominated the non-Gradle part of an all install. The versionCodeOverride probe ran two adb round trips per module (146 calls for all; measured 0.29s per call over the forwarded transport, ~45s before Gradle started) and now fetches the full package/versionCode list and the system-package set in two calls, falling back to the per-package queries if a batch returns nothing. APK session installs were likewise one-at-a-time (a push plus four pm round trips each); they now run INSTALL_JOBS (default 4) at a time in waves, with per-module failure markers preserving the success count. INSTALL_JOBS=1 restores serial installs. The Gradle invocation is unchanged (already a single --continue invocation over all modules). Verified: bash -n, --dry-run dev 9 notes camera, and the batched parsing checked against the live Pixel 9 package list (notes versionCode and system/user classification correct). No device installs were run.
Diff
install
diff --git a/install b/installindex 7964a6d238..042f3d07bc 100755--- a/install+++ b/install@@ -705,13 +705,30 @@ fi REPO_VERSION="$(sed -n '1p' "$ROOT/version.txt" | tr -d '\r' | xargs)" NEED_BUMP="$REPO_VERSION" if [[ -n "$TARGET_SERIAL" ]]; then+ # Batch the device queries: one `pm list packages` for every package's+ # versionCode and one for the system-package set, instead of two adb+ # round trips per module (146 calls for `all`, ~0.3s each over the+ # forwarded transport — ~45s of pure latency before Gradle even starts).+ # Falls back to the per-package queries if a batch call returns nothing.+ ALL_PKG_VERSIONS="$(adb_dev shell pm list packages --show-versioncode 2>/dev/null || true)"+ SYSTEM_PKGS="$(adb_dev shell pm list packages -s 2>/dev/null || true)"+ batched_version_code() {+ printf '%s\n' "$ALL_PKG_VERSIONS" | awk -v k="package:$1" '$1 == k { sub(/^versionCode:/, "", $2); print $2; exit }'+ }+ batched_is_system_app() {+ printf '%s\n' "$SYSTEM_PKGS" | grep -qxF "package:$1"+ } idx=0 while [[ $idx -lt ${#NORMALIZED_MODULES[@]} ]]; do pkg="$(module_application_id "${NORMALIZED_MODULES[$idx]}")" if [[ -n "$pkg" ]]; then- dev_v="$(device_version_code "$pkg")"+ if [[ -n "$ALL_PKG_VERSIONS" ]]; then+ dev_v="$(batched_version_code "$pkg")"+ else+ dev_v="$(device_version_code "$pkg")"+ fi if [[ -n "$dev_v" && "$dev_v" -ge "$NEED_BUMP" ]]; then- if is_system_app "$pkg"; then+ if { [[ -n "$SYSTEM_PKGS" ]] && batched_is_system_app "$pkg"; } || { [[ -z "$SYSTEM_PKGS" ]] && is_system_app "$pkg"; }; then target=$((dev_v + 1)) kind="system app" else@@ -764,19 +781,45 @@ if [[ $BUILD_EXIT -ne 0 ]]; then fi TOTAL=${#NORMALIZED_MODULES[@]} echo ""-echo "Installing $TOTAL app(s) to $TARGET_SERIAL..."-idx=0-while [[ $idx -lt ${#NORMALIZED_MODULES[@]} ]]; do- mod="${NORMALIZED_MODULES[$idx]}"- cur=$((idx + 1))+# Session installs run INSTALL_JOBS at a time (default 4): every install is+# a push plus four `pm` round trips over the forwarded transport, so serial+# installs spent minutes on latency alone for `all`. PackageManager accepts+# concurrent sessions; pushes share the transport but overlap the round+# trips. Set INSTALL_JOBS=1 for the old serial behaviour.+INSTALL_JOBS="${INSTALL_JOBS:-4}"+case "$INSTALL_JOBS" in ""|*[!0-9]*|0) INSTALL_JOBS=4;; esac+echo "Installing $TOTAL app(s) to $TARGET_SERIAL (${INSTALL_JOBS} at a time)..."+install_one() {+ local mod="$1" cur="$2" apk if apk="$(built_apk "$mod")"; then- install_apk_via_session "$apk" "$(module_application_id "$mod")" "$cur" "$TOTAL" || FAILURES=$((FAILURES + 1))+ install_apk_via_session "$apk" "$(module_application_id "$mod")" "$cur" "$TOTAL" else echo "[$cur/$TOTAL] Error: no APK found for :${mod} (assemble failed?)."- FAILURES=$((FAILURES + 1))+ return 1 fi- idx=$((idx + 1))-done+}+if [[ "$INSTALL_JOBS" -gt 1 && $TOTAL -gt 1 ]]; then+ FAIL_DIR="$(mktemp -d)"+ idx=0+ while [[ $idx -lt ${#NORMALIZED_MODULES[@]} ]]; do+ wave_end=$((idx + INSTALL_JOBS))+ if [[ $wave_end -gt $TOTAL ]]; then wave_end=$TOTAL; fi+ while [[ $idx -lt $wave_end ]]; do+ mod="${NORMALIZED_MODULES[$idx]}"+ ( install_one "$mod" "$((idx + 1))" || touch "$FAIL_DIR/$idx" ) &+ idx=$((idx + 1))+ done+ wait+ done+ FAILURES=$(find "$FAIL_DIR" -type f | wc -l | tr -d ' ')+ rm -rf "$FAIL_DIR"+else+ idx=0+ while [[ $idx -lt ${#NORMALIZED_MODULES[@]} ]]; do+ install_one "${NORMALIZED_MODULES[$idx]}" "$((idx + 1))" || FAILURES=$((FAILURES + 1))+ idx=$((idx + 1))+ done+fi if [[ $FAILURES -gt 0 ]]; then echo "" echo "Install complete: $((TOTAL - FAILURES))/$TOTAL succeeded, $FAILURES failed."