Startup Profiles are a subset of Baseline Profiles. Startup Profiles are used by
the build system to further optimize the classes and methods they contain by
improving the layout of code in your APK's DEX files. With Startup Profiles,
your app startup is usually between 15% and 30% faster than with Baseline
Profiles alone.

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

## Requirements

We recommend using Startup Profiles with the following tools:

- Jetpack Macrobenchmark 1.2.0 or higher
- Android Gradle Plugin (AGP) 8.2 or higher
- Android Studio Iguana or higher

In addition, you need the following settings in your app:

- [R8](https://developer.android.com/build/shrink-code) enabled. For your release build, set `isMinifyEnabled = true`.
- DEX layout optimizations enabled. This is available only starting from AGP 8.1, and is enabled by default since AGP 8.3. For AGP versions 8.1 to 8.2, in the `baselineProfile {}` block of the app module's build file, set `dexLayoutOptimization = true`.

## Create a Startup Profile

> [!NOTE]
> **Note:** Unlike regular Baseline Profiles, Startup Profiles can't be contributed by libraries. Startup Profiles only include rules generated by the startup tests that you define, so make sure that you include all the main ways that users can enter your app.

> [!NOTE]
> **Note:** AGP 8.2 doesn't support distinct Startup Profiles per variant. If you're using AGP 8.2, use Baseline Profile Gradle plugin 1.2.3 or higher to automatically merge across variants. Upgrade to AGP 8.3 to use distinct Startup Profiles per variant.

Android Studio creates a Startup Profile alongside a Baseline Profile when you
use the default Baseline Profile Generator template.

The general steps to create and generate a Startup Profile are the same as those
to [create a Baseline Profile](https://developer.android.com/topic/performance/baselineprofiles/create-baselineprofile).

The default way to create a Startup Profile is by using the Baseline Profile
Generator module template from within Android Studio. This includes startup
interactions that form a basic Startup Profile. To augment this Startup Profile
with more Critical User Journeys (CUJs), add your app startup CUJs to a `rule`
block with `includeInStartupProfile` set to `true`. For simple apps, launching
the app's `MainActivity` might be sufficient. For more complex apps, consider
adding the most common entry points into your app, such as starting the app from
the home screen or launching into a [deep link](https://developer.android.com/training/app-links/deep-linking).

The following code snippet shows a Baseline Profile generator (by default the
`BaselineProfileGenerator.kt` file) that includes starting your app from the
home screen and launching into a deep link. The deep link goes directly to the
app's news feed, not the app's home screen.

    @RunWith(AndroidJUnit4::class)
    @LargeTest
    class BaselineProfileGenerator {

        @get:Rule
        val rule = BaselineProfileRule()

        @Test
        fun generate() {
            rule.collect(
                packageName = "com.example.app",
                includeInStartupProfile = true
            ) {
                uiAutomator {
                    // Launch directly into the NEWS_FEED using startActivityIntent
                    startIntent(Intent().apply {
                        setPackage(packageName)
                        setAction("com.example.app.NEWS_FEED")
                    })
            }
        }
    }

Run the [**Generate Baseline Profile for app** configuration](https://developer.android.com/topic/performance/baselineprofiles/create-baselineprofile#generate-profile) and find the
Startup Profile rules at
`src/<variant>/generated/baselineProfiles/startup-prof.txt`, where they are
automatically consumed by AGP.

## Considerations to creating startup profiles

> [!TIP]
> **Tip:** For the most performance improvement, try to limit the user journeys added to your startup profile so that you stay within one DEX file.

> [!NOTE]
> **Note:** To get the highest impact performance improvement from startup profile, the startup code should fit into the `classes.dex` file, which is the first DEX file. If that's not possible, the startup code will overflow into the next DEX files, which are then filled up with other classes and methods. To find out if this happens, and what you can do to reduce your app's startup size to make it start faster, see [Confirm Startup Profiles optimization](https://developer.android.com/topic/performance/baselineprofiles/confirm-startup-profiles).

To decide which user journeys to cover when creating a startup profile, consider
where most users start the application. Usually that is from the launcher and
after they have been logged in. This is also the most basic baseline profile
journey.

After the first use case has been covered, follow the user funnel for app
startup. In many cases, app startup funnels follow this list:

1. Main launcher activity
2. Notifications that trigger app startup
3. Optional launcher activities

Work this list from the top and stop before `classes.dex` is full. To cover more
journeys afterwards, move code out of the startup path and add more journeys. To
move code out of the startup path, inspect Perfetto traces during app startup
and look for long running operations. You can also use a [macrobenchmark](https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview)
with [method tracing enabled](https://developer.android.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args#profiling-mode) for an automatable and complete view of method
calls during app startup.

## Recommended for you

- Note: link text is displayed when JavaScript is off
- [Create Baseline Profiles {:#creating-profile-rules}](https://developer.android.com/topic/performance/baselineprofiles/create-baselineprofile)
- [Baseline Profiles {:#baseline-profiles}](https://developer.android.com/topic/performance/baselineprofiles/overview)
- [Writing a Microbenchmark](https://developer.android.com/topic/performance/benchmarking/microbenchmark-write)