The fastest Android performance win that is still under-used is a Baseline Profile. It tells Cloud Profile (Play / ART) which methods and classes your app actually uses on a cold start or a critical user journey, so ART can ahead-of-time compile them instead of interpreting or JIT-ing them on the first run.
This is not a micro-benchmark of a tight loop. It is a way to make first frames and first navigations feel like a second-session app.
Advertisement
What a Baseline Profile is
A Baseline Profile is a human-readable list of methods and classes, shipped in the APK or AAB as baseline-prof.txt (and compiled into baseline.prof). On install or first use, ART uses it to pre-compile those methods. Android 7 and later can use profiles; the modern toolchain (AGP, Jetpack baselineprofile, Macrobenchmark) is what you want on current apps.
Google's documented results are typically in the 10–30% range for startup and frame timing on first runs, depending on the app. Treat those as a reason to measure your app, not as a guarantee.
The two modules you add
The current Jetpack recommendation is a Macrobenchmark module plus a Baseline Profile generator module that exercises the same journeys.
// baselineprofile/build.gradle.kts (simplified)
plugins {
id("com.android.test")
id("androidx.baselineprofile")
}
android {
defaultConfig {
minSdk = 28
}
targetProjectPath = ":app"
}
dependencies {
implementation("androidx.benchmark:benchmark-macro-junit4:1.3.3")
implementation("androidx.test.uiautomator:uiautomator:2.3.0")
}The generator test looks like a UI Automator script:
@RunWith(AndroidJUnit4::class)
class BaselineProfileGenerator {
@get:Rule
val rule = BaselineProfileRule()
@Test
fun startupAndOpenArticle() {
rule.collect(packageName = "com.example.androidlearner") {
startActivityAndWait()
device.findObject(By.text("Compose")).click()
device.wait(Until.hasObject(By.res("article-body")), 5_000)
}
}
}BaselineProfileRule.collect starts the app, runs your block, and records the classes and methods that were loaded. Keep the journey honest: cold start, then the two or three screens a new user actually opens. Do not click every debug menu you have.
Measure first, then claim a win
A profile you never measure is a hope. Use Macrobenchmark's StartupTimingMetric and FrameTimingMetric:
@RunWith(AndroidJUnit4::class)
class ColdStartBenchmark {
@get:Rule
val benchmark = MacrobenchmarkRule()
@Test
fun coldStartup() {
benchmark.measureRepeated(
packageName = "com.example.androidlearner",
metrics = listOf(StartupTimingMetric()),
iterations = 8,
startupMode = StartupMode.COLD,
compilationMode = CompilationMode.Partial(
baselineProfileMode = BaselineProfileMode.Require,
),
) {
startActivityAndWait()
}
}
}Run the same test with CompilationMode.None() (or CompilationMode.Ignore() on newer libraries) as a control so you can see what the profile actually changed. Do this on a real device. Emulators will not give you numbers you can ship a blog post with.
Things people miss
- Ship the profile. The
androidx.baselineprofileGradle plugin (andBaselineProfileConsumeron the app module in current AGP) packages the generatedbaseline-prof.txt. If it is not in the AAB, Play cannot use it. - Keep journeys short and representative. A 40-step generator that wanders into settings will bloat the profile and dilute the benefit for startup.
- R8 / minification and the profile work together. Baseline Profiles complement, they do not replace, shrinking and the usual startup hygiene (do less in
Application.onCreate(), defer work, watch for disk I/O on the main thread). - Cloud Profiles still matter. Play collects real-user profiles and can improve compilation further after install. Your Baseline Profile is the first-run safety net, not a replacement for that system.
- Compose and libraries. If you use Compose, Navigation, and Hilt, include a journey that first-composes a typical screen. Those libraries are large; precompiling the path you actually use is most of the win.
A practical rollout
- Add a Macrobenchmark module and measure cold start as it is today.
- Add a Baseline Profile generator for startup plus one critical journey.
- Generate the profile on a pinned, representative device or in CI with a managed device.
- Re-run the benchmark with
CompilationMode.Partialand keep the profile only if the metric moved in the right direction. - Regenerate the profile when you change that journey significantly (a new home screen, a new login graph).
Baseline Profiles are not a substitute for fixing a 400 ms main-thread database query. They are the cheapest way to make a well-behaved app feel compiled on the first launch. Measure, generate, ship, measure again.


