This document explains the difference between Baseline Profiles and Startup
Profiles.

You can use the Baseline Profile Gradle Plugin to automatically capture the
human-readable baseline profile files generated by [`BaselineProfileRule`](https://developer.android.com/reference/kotlin/androidx/benchmark/macro/junit4/BaselineProfileRule)
tests. When building the app, Android Gradle Plugin (AGP) compiles these
human-readable profile rules into a binary format, packaged as `baseline.prof`
within the Android Package Kit (APK) or Android App Bundle (AAB), that Android
Runtime (ART) can use effectively for on-device compilation, provided the binary
profile is smaller than 1.5 MB.

The profile files produced are typically named `startup-prof.txt` and
`baseline-prof.txt`.

## Baseline Profile

The Baseline Profile file contains a comprehensive set of rules that ART uses to
pre-compile frequently used code paths, which optimizes app startup, reduces
interaction jank, and improves the overall runtime performance.

The Baseline Profile file is generally a superset of the rules found in your
Startup Profile. This file includes all rules required for app startup
optimization (generated through the `baselineProfile` Gradle task), along with
additional profiles for other critical user journeys. For example, scrolling,
and navigating different screens.

These non-startup rules are generated regardless of the value of the
[`includeInStartupProfile`](https://developer.android.com/topic/performance/baselineprofiles/create-baselineprofile#define-generator) configuration field. For more information, see
[Overview of Baseline Profiles](https://developer.android.com/topic/performance/baselineprofiles/overview).

## Startup Profile

The Startup Profile file contains rules specifically optimized for your app's
startup path. During compilation, D8 and R8 consume Java bytecode to produce
[Dalvik executable (DEX)](https://source.android.com/docs/core/runtime/dex-format) files. Both D8 and R8 use Startup Profiles to
optimize DEX layout by placing critical startup code in the primary `.dex` file
for faster class loading. To achieve the most significant performance gains, the
startup code must be contained within this primary `.dex` file. If the
cumulative size of the startup code is too large, it overflows into subsequent
DEX files, which are often populated with non-essential classes and methods and
slows down startup.

While a Startup Profile provides the metadata necessary for DEX layout
optimization, R8 code optimization can be highly effective in assisting this
process. By removing unused code and minifying bytecode, R8 reduces the total
footprint of the startup logic. This reduction increases the likelihood that the
critical code remains within the primary `.dex` file, preventing overflow and
ensuring more efficient execution across a broader range of Android versions.
You should generally set [`includeInStartupProfile`](https://developer.android.com/topic/performance/baselineprofiles/create-baselineprofile#define-generator) to `true` only for test
scenarios essential to the app's initial display.

For more information, see [Overview of Startup Profiles](https://developer.android.com/topic/performance/startupprofiles/overview).