# CompilationMode

Artifact: [androidx.benchmark:benchmark-macro](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/macro/CompilationMode.kt+class:androidx.benchmark.macro.CompilationMode) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.1.0)

*** ** * ** ***


```
public sealed class CompilationMode
```

<br />

Known direct subclasses [CompilationMode.Full](https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Full), [CompilationMode.Ignore](https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Ignore), [CompilationMode.None](https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.None), [CompilationMode.Partial](https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial)

|---|---|
| `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Full` | Full ahead-of-time compilation of all method (but not classes) in the target application. |
| `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Ignore` | This compilation mode doesn't perform any reset or compilation, leaving the user the choice to implement these steps. |
| `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.None` | No pre-compilation - a compilation profile reset is performed and the entire app will be allowed to Just-In-Time compile as it runs. |
| `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial` | Partial ahead-of-time app compilation. |

*** ** * ** ***

Type of compilation to use for a Macrobenchmark.

This compilation mode controls pre-compilation that occurs before running the setup / measure blocks of the benchmark.

On Android N+ (API 24+), there are different levels of compilation supported:

- `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial` - the default configuration of `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial` will partially pre-compile your application, if a Baseline Profile is included in your app. This represents the most realistic fresh-install experience on an end-user's device. You can additionally or instead use `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial#warmupIterations()` to use Profile Guided Optimization, using the benchmark content to guide pre-compilation. This can mimic an application's performance after background dexopt has partially compiled the app during device idle time, after the app has been used (generally after a day or more of usage after update/install).

- `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Full` - the app is fully pre-compiled. This is generally not representative of real user experience, as apps are not fully pre-compiled on user devices more recent than Android N (API 24). `Full` can be used to show unrealistic but potentially more stable performance by removing the noise/inconsistency from just-in-time compilation within benchmark runs. Note that `Full` compilation will often be slower than `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial` compilation, as the increased code size creates more cost for disk loading during startup, and increases pressure in the instruction cache.

- `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.None` - the app isn't pre-compiled at all, bypassing the default compilation that should generally be done at install time, e.g. by the Play Store. This will illustrate worst case performance, and will show you performance of your app if you do not enable baseline profiles, useful for judging the performance impact of the baseline profiles included in your application.

- `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Ignore` - the state of compilation will be ignored. The intended use-case is for a developer to customize the compilation state for an app; and then tell Macrobenchmark to leave it unchanged.

On Android M (API 23), only `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Full` is supported, as all apps are always fully compiled.

To understand more how these modes work, you can see comments for each class, and also see the [Android Runtime compilation modes](https://source.android.com/devices/tech/dalvik/configure#compilation_options) (which are passed by benchmark into [`cmd compile`](https://source.android.com/devices/tech/dalvik/jit-compiler#force-compilation-of-a-specific-package) to compile the target app).

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Full extends https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode` Full ahead-of-time compilation of all method (but not classes) in the target application. |
| `@https://developer.android.com/reference/androidx/benchmark/macro/ExperimentalMacrobenchmarkApi public final class https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Ignore extends https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode` This compilation mode doesn't perform any reset or compilation, leaving the user the choice to implement these steps. |
| `public final class https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.None extends https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode` No pre-compilation - a compilation profile reset is performed and the entire app will be allowed to Just-In-Time compile as it runs. |
| `public final class https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial extends https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode` Partial ahead-of-time app compilation. |

| ### Public fields |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode` | `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode#DEFAULT()` Represents the default compilation mode for the platform, on an end user's device. |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode#CompilationMode()()` |

## Public fields

### DEFAULT

```
public static final @NonNull CompilationMode DEFAULT
```

Represents the default compilation mode for the platform, on an end user's device.

This is a post-store-install app configuration for this device's SDK version - `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial` on API 24+, and `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Full` prior to API 24 (where all apps are fully AOT compiled).

On API 24+, Baseline Profile pre-compilation is used if possible, but no error will be thrown if installation fails.

Generally, it is preferable to explicitly pass a compilation mode, such as `https://developer.android.com/reference/androidx/benchmark/macro/CompilationMode.Partial` to avoid ambiguity, and e.g. validate an app's BaselineProfile can be correctly used.

## Protected constructors

### CompilationMode

```
protected CompilationMode()
```