Add a macrobenchmark module, and find out what the build was hiding

docs/PERFORMANCE.md has been honest that three of its four numbers do not exist. They exist now as
measurements, if not yet as results: benchmark/ is a macrobenchmark module with four tests - cold start
with StartupTimingMetric, then opening, scrolling and searching a folder of a thousand files with
FrameTimingMetric - sharing a fixture at /sdcard/AABenchmark that is created once per run and deleted in
@AfterClass. Frames rather than a named trace section on purpose: what a user calls slow is jank on
screen, and the alternative puts benchmarking calls into production code for the sake of a number.
CompilationMode.None() is the honest cold-install baseline; Partial() plus a baseline profile is the
follow-up and needs the same module. The storage grant is applied with appops in setup, which is what
lets the run be unattended - a permission dialog is the one thing a test cannot answer.

Three build facts had to be discovered rather than designed, and each is now written where it will be
read. The app under test cannot keep its own package id: it needs a debug signature to install on a test
device, so it cannot replace a release install, and an un-suffixed build is exactly that. It also cannot
use the obvious suffix: `.benchmark` is already the benchmark module's own APK id, and the test APK then
fails to install with INSTALL_FAILED_VERSION_DOWNGRADE - which is what the first attempt did. Hence
`.perf`. And `testBuildType = "benchmark"` cannot be set unconditionally, because it makes benchmark the
variant that *unit* tests run against and :app:testDebugUnitTest - the task the entire gate is built on -
stops existing; it is behind -PbenchmarkBuild instead. All three were measured, not guessed, and the
third would have broken CI silently.

Two smaller things came with it. tools/verify.sh --release now also compiles the app's benchmark variant
and the test APK, because build wiring nobody runs is wiring that rots; no device is involved. And the
code map grew an EXTRA_ROOTS section so it indexes benchmark/ too - a map that silently omits a module
lies by omission, which is worse than the one line it costs.

The numbers themselves are still missing, and for a device reason rather than a code one: installing the
new package id on this MIUI phone fails with INSTALL_FAILED_USER_RESTRICTED (the "Install via USB" gate,
which wants a human and answered too late). Both APKs are pushed to /sdcard/Download/ for a manual
install, and the run is one command away:
`adb shell am instrument -w -e class de.softwareapp_hb.filemanager.benchmark.BrowserBenchmark de.softwareapp_hb.filemanager.benchmark/androidx.test.runner.AndroidJUnitRunner`.

Gate green with --release, including the new compile step; map current; 386 tests unchanged.
This commit is contained in:
2026-10-17 09:45:36 +02:00
parent 0bbee25ab3
commit 1f94d0a38a
13 changed files with 406 additions and 4 deletions
+34
View File
@@ -95,6 +95,26 @@ android {
"proguard-rules.pro",
)
}
/*
* What macrobenchmark measures: release rules (R8 on, not debuggable) but signed with the
* debug key so it can be installed on a test device. The manifest in src/benchmark adds the
* one thing a benchmark cannot work without — `<profileable android:shell="true"/>`.
*
* The suffix is not cosmetic, and it is `.perf` rather than `.benchmark` on purpose: the
* benchmark module's own APK is `de.softwareapp_hb.filemanager.benchmark`, so an app under
* test with that id collides with the test APK and the install fails with
* INSTALL_FAILED_VERSION_DOWNGRADE. Without a suffix at all, this build would have the app's
* own package id and a debug signature — which cannot be installed beside a release build,
* and would replace a release install if the keys happened to match. A benchmark must never be
* able to take over the shipped app.
*/
create("benchmark") {
initWith(getByName("release"))
applicationIdSuffix = ".perf"
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("release")
isDebuggable = false
}
}
compileOptions {
@@ -102,6 +122,20 @@ android {
targetCompatibility = JavaVersion.VERSION_17
}
/*
* Which build type the instrumentation tests run against — only when asked for.
*
* Setting this unconditionally also makes `benchmark` the variant that *unit* tests run against,
* and `:app:testDebugUnitTest` — the task the gate and CI are built on — stops existing. That is
* measured rather than guessed: with it set, the only unit-test task left was
* `testBenchmarkUnitTest`.
*
* ./gradlew -PbenchmarkBuild :benchmark:connectedDebugAndroidTest
*/
if (providers.gradleProperty("benchmarkBuild").isPresent) {
testBuildType = "benchmark"
}
buildFeatures {
compose = true
}