Skip to content

perf: enable Android emulator Quick Boot - #359

Draft
janicduplessis wants to merge 3 commits into
mainfrom
@janic/issue-284-emulator-snapshots
Draft

perf: enable Android emulator Quick Boot#359
janicduplessis wants to merge 3 commits into
mainfrom
@janic/issue-284-emulator-snapshots

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Description

Owned Android AVDs cold-boot on every restart because Stim disables both Quick Boot loading and saving, adding about 22 seconds in the measurements from #284.

The flags were added in PR #93 to reduce AVD storage (commit lines), before Stim measured and configured owned-AVD userdata. This PR depends on #357 because Quick Boot saves state during graceful shutdown; the guest-write flush must merge first.

Solution

Use Android Emulator's default Quick Boot policy for owned AVDs except on displayless Linux, where Stim's required software renderer is incompatible with snapshots. A new AVD or an invalid snapshot cold-boots; later supported restarts load the single automatic snapshot saved on exit. Android invalidates snapshots after emulator, system-image, or AVD-setting changes (Android snapshot documentation).

adb emu kill returns before emulator shutdown necessarily finishes. Teardown now reads the exact emulator PID from the owned AVD's active process lock before sending the shutdown request, then waits up to 60 seconds for both the bounded adb command and that process to exit. Emulator process exit occurs after the Quick Boot save. Offline emulators are resolved through their console identity; an ADB-invisible live process, a timeout, or an AVD relaunched before deletion keeps the ownership record and prevents deletion.

New owned AVDs default to an 8 GiB data partition, project settings can choose another size, and existing AVDs keep their configured size. When enabled, Quick Boot keeps one automatic snapshot; stim worktree remove deletes the whole AVD, and stim gc reports the size of stale or orphaned owned AVDs. The benchmark control prompt now uses the same policy.

Test plan

  • Quick Boot timing was not re-measured because no Stim-owned Android AVD was available. Android Emulator 35.6.11 accepted -avd stim-issue-284-verification -port 5580 and failed only because that deliberately nonexistent AVD was absent; no installed device was touched.
  • Shutdown tests cover the primary and legacy AVD lock formats, Windows paths, offline and ADB-invisible emulators, bounded commands, continued liveness, successful exit, timeout, and pre-deletion relaunch checks.
  • Format, lint, build, typecheck, and all 3,530 unit tests pass; the 20 repository e2e tests pass.

Fixes #284.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android emulators always boot with snapshots disabled, costing about 22 s per reboot

1 participant