Baseline Profiles

On this page 7

Baseline Profiles are lists of classes and methods, shipped inside an Android app, that tell the Android Runtime (ART) which code to compile to machine code ahead of time at install, instead of interpreting it or waiting for the just-in-time compiler. In mobile performance engineering they are one of the most effective tools for reducing app startup time and jank on the very first launch, before the device has collected any usage data of its own.

The technique belongs to the Mobile platform toolchain maintained by the Jetpack libraries and the Android Gradle Plugin. A profile is generated by driving real user journeys on a test device, recorded in a human-readable rules file, packaged with the APK or Android App Bundle, and consumed by the system compiler dex2oat during or shortly after installation.

How Baseline Profiles guide ART compilation

Baseline Profiles work by seeding profile-guided compilation with knowledge the developer already has. Since Android 7.0, ART uses a hybrid model: code starts in the interpreter, hot methods are compiled by the JIT compiler, and the runtime records which methods were used. During idle maintenance, typically while the device charges, the system compiles that recorded code with the speed-profile filter.

Without a profile, a fresh install therefore runs largely interpreted or JIT-compiled code for the first days of use. A Baseline Profile removes that warm-up period: the rules file lists the methods needed for startup and key interactions, so dex2oat compiles them at install time and the very first launch already executes optimized machine code.

The following table shows how the main ART execution modes compare and where a Baseline Profile changes the picture.

Execution modeWhen it appliesPerformance effect
InterpreterCode never compiled beforeSlowest path, high CPU cost per call
JIT compilationHot code at run timeFast after warm-up, but compiles during use
Profile-guided AOTCode listed in a profileOptimized from first execution
Full AOTEntire app compiledFast, but larger storage and longer installs
ART execution modes and the role of a profile

Profile rules, files and delivery paths

A Baseline Profile is authored as a plain text file, baseline-prof.txt, in which each line is a class or method descriptor with flags. The flag H marks a hot method, S a method used during startup, and P a method used after startup. Wildcards allow whole packages to be covered, which is how libraries such as Jetpack Compose ship their own rules.

At build time the Android Gradle Plugin merges the app rules with profiles bundled in dependencies, rewrites names to match the R8 obfuscation mapping, and converts the result into a binary profile stored under assets/dexopt/ as baseline.prof and baseline.profm. The table below summarizes how the profile reaches the device.

Delivery pathMechanismTypical timing
Google Play installPlay passes the profile to the installerApplied at install time
Cloud profilesPlay aggregates usage profiles from early usersAvailable days after a release
ProfileInstaller libraryWrites the profile for non-Play installsApplied on a later background compile
Local testingForced compilation through shell commandsImmediate, for benchmarking only
How a Baseline Profile reaches the device

Cloud profiles and Baseline Profiles complement each other. Cloud profiles reflect aggregated behavior of real users, but they only exist after enough installs of a given version, so the first users of every release benefit mostly from the shipped Baseline Profile.

Generating and measuring a profile

Profiles are generated with the Macrobenchmark library and its BaselineProfileRule, usually through the androidx.baselineprofile Gradle plugin. A test module launches the release build, performs critical user journeys such as startup, scrolling a feed or opening a detail screen, and collects the methods ART actually executed. Generation requires a rooted device, a userdebug build or an emulator running a recent Android version.

Measurement uses the same library with different compilation modes, which makes the benefit visible and reproducible. The comparison below is the standard way to prove that a profile helps before shipping it.

Compilation modeWhat it simulatesUse in evaluation
NoneA fresh install without any profileWorst-case baseline
Partial with profile requiredInstall with the Baseline Profile appliedExpected first-launch result
FullEvery method compiled ahead of timeUpper bound, not a shipping target
IgnoreCurrent device state left untouchedDebugging only, results not comparable
Macrobenchmark compilation modes used to validate a profile

Teams commonly report startup improvements of roughly 20 to 40 percent and smoother first scrolls, but the gain depends on app size, device class and how much code runs before the first frame. Results are most pronounced on low-end devices with slower CPUs and storage, which is also where Android vitals thresholds are hardest to meet.

Baseline Profiles address code execution speed, which distinguishes them from neighboring tools in the Topic. R8 and the older ProGuard shrink and optimize bytecode, while Startup Profiles are a related artifact that R8 uses to reorder DEX files so startup classes sit together in the primary DEX.

TechniqueWhat it optimizesRelation to Baseline Profiles
R8 shrinkingBytecode size and inliningRuns first; profile names follow its mapping
Startup ProfilesDEX layout for startup classesGenerated by the same benchmark setup
Cloud profilesCompilation from field usageSupplement shipped rules over time
Hermes bytecodeJavaScript execution in React NativeSeparate engine, unaffected by ART profiles
Related Android performance techniques

Profilers such as Perfetto and the Android Studio Profiler remain essential, because a profile only speeds up code that is already necessary. Blocking disk reads, heavy dependency injection graphs or synchronous network calls during startup still need to be removed at the source.

Limitations and common mistakes

Baseline Profiles are not a universal accelerator, and several practical pitfalls reduce or hide their effect. The most frequent issues seen in production projects are listed below.

  • Stale profiles: rules generated months ago miss new screens, so the profile should be regenerated with each release in continuous integration.
  • Overly broad rules: wildcard rules covering entire packages inflate compiled code, increase install time and can raise app size on disk.
  • Debug-build measurements: debuggable builds disable many runtime optimizations, so benchmarks must use a release-like, non-debuggable variant.
  • Missing ProfileInstaller: apps distributed outside Google Play need the library, or the profile may never be applied.
  • Unrealistic journeys: generating the profile from a test path users rarely take compiles the wrong code and leaves real startup interpreted.

A further limit is platform scope: profile-guided ART compilation applies to Android 7.0 (API level 24) and later, and the mechanism has no counterpart on iOS, where apps are already compiled to native code before distribution.

Put simply

A new Android app runs slowly at first. The phone must translate much of its code on the fly. It is like reading a recipe in a foreign language with a dictionary in hand.

A Baseline Profile is a cheat sheet from the developer. It says which parts of the recipe are needed first. The phone translates those parts in advance during installation. As a result, the app opens faster from day one. It does not need several days of use to become quick.

In practice

A mid-sized retail app team notices in Android vitals that cold startup on budget phones often exceeds two seconds after each release. Their Macrobenchmark suite measures a median cold start of about 1,450 milliseconds on a low-end test device with compilation mode None.

The team adds a baseline profile module that covers launch, scrolling the product feed and opening a product page, and runs it in continuous integration for every release build. With the profile applied, the median cold start falls to roughly 1,000 milliseconds and frame drops during the first feed scroll decrease visibly. The outcome is a startup reduction of about 30 percent for first-time users, achieved without changing any feature code.