skip to content

As an Android lead, which Jetpack Benchmark suites would you run in CI to gate a release, and what Baseline Profile regeneration policy would you set?

level: principalimportance: should knowfreq 24%

answer

  1. results are a time series
  2. dry run on every pull request
  3. real devices, medians, step changes
  4. gate with Partial(Require)
  5. regenerate per release or commit

basics

~20 s

Dry-run benchmarks on every pull request, run startup and scroll macrobenchmarks plus a few microbenchmarks nightly on one physical device model, and gate releases on median trends under Partial(BaselineProfileMode.Require). Regenerate the Baseline Profile per release or on a reviewed cadence.

solid answer

~40 s

I treat benchmark output as a time series, not a pass or fail. Every pull request runs the suites with `androidx.benchmark.dryRunMode.enable=true`, one cheap iteration that proves they still run. Nightly or per merge, a pinned physical device model runs a cold-start benchmark with `StartupTimingMetric`, a feed scroll with `FrameTimingMetric` and a few microbenchmarks for hot code, and we track medians and persistent steps instead of one-run thresholds. The release gate uses `CompilationMode.Partial(BaselineProfileMode.Require)`, which also fails if the profile is missing, with a `None()` run to show its value. For the profile, I pick between `automaticGenerationDuringBuild` and a committed `saveInSrc` profile regenerated per release branch, weighing build time against drift.

go deeper

for a junior

Recall that benchmark results are numbers to track over time on real devices, not a pass or fail like a unit test.

for a middle

Explain dry run mode, why medians and a fixed device model matter, and what Partial with Require proves in CI.

for a senior

Show how you would separate noise from a real regression with trends, iterations and traces before anyone blocks a release.

for a principal

Own the trade between device-farm cost, build time and signal quality, and set who regenerates and reviews the Baseline Profile and when.

## The decision Benchmarks only protect a release if someone runs them, reads them and acts on them. As the Android lead you decide which Jetpack Benchmark suites run where, what result blocks a release, and how the team's Baseline Profile is kept current. There is no single right answer: the trade is between confidence, CI cost and how often a noisy number blocks a good release. ## What benchmark results are, and are not Benchmarks are instrumented tests, but their output is not pass or fail. Each run writes a `*-benchmarkData.json` file with minimum, median, maximum and every iteration's value, plus per-iteration trace files. Those numbers move with the device, its temperature, background work and the data set. Treat them as a time series: - **Pin the hardware**: one physical device model, never an emulator, which both libraries reject unless the error is suppressed. - **Use enough iterations** and track the **median**; a single slow iteration is noise. - **Detect steps across several runs** instead of failing a build on one result crossing a fixed threshold; a step that persists over consecutive builds is a regression, a spike that vanishes is not. - **Steady the device** for microbenchmarks: `./gradlew lockClocks` on a rooted device, otherwise rely on the library's thermal-throttling detection and sustained performance mode. ## A tiered suite A common shape, which each team tunes to its budget: 1. **On every pull request**: run the benchmark modules with `androidx.benchmark.dryRunMode.enable=true`. Dry run mode runs one iteration, skips compilation, suppresses configuration errors and writes no JSON results. It costs little and catches a broken benchmark (a renamed resource id the scroll can no longer find) before it silently stops measuring. 2. **On the main branch, nightly or per merge, on real devices**: the journeys users feel. A cold-start macrobenchmark with `StartupTimingMetric`, a frame benchmark for the busiest screen with `FrameTimingMetric`, and a short list of microbenchmarks for hot code the team tunes, such as a feed parser. 3. **Before a release**: compare the release candidate's medians against the last release. This is where a blocking decision belongs, after a person has looked at the trend. Running the full suite on every pull request sounds safer, but the device time and the noise usually make reviewers ignore it. ## Gate on the compilation state users get The release gate should measure what an install from the store looks like: `CompilationMode.Partial(BaselineProfileMode.Require)`. It doubles as a **configuration check**, because it throws if the Baseline Profile or ProfileInstaller is missing, where the default `UseIfAvailable` would log and continue. Keep a `CompilationMode.None()` run alongside it to show what the profile is worth; if that gap shrinks release over release, the profile has gone stale. ## The Baseline Profile policy The team also has to decide when the profile is regenerated: | Policy | How | Gains | Costs | |---|---|---|---| | Regenerate on every release build | `automaticGenerationDuringBuild = true` | profile always matches the code | longer release builds; a device or managed device in the release pipeline | | Regenerate on a cadence, commit to source | `saveInSrc = true`, run `generateBaselineProfile`, review the diff | reviewable, reproducible builds | can drift between runs | | Generate by hand when someone remembers | none | no pipeline cost | goes stale after dependency upgrades | Whichever policy you choose, write down: - **which journeys** the generators cover (startup with `includeInStartupProfile = true`, plus the main feed scroll), and that generators share journey code with the benchmarks; - **which device** generates them: Android 13 or later, or a rooted device on API 28 or later; - **who reviews** a large change in `baseline-prof.txt`, since a sudden shrink usually means a journey stopped running. ## Making the call Weigh the release cadence, the size of the device farm and how much startup matters to the product. A small team often gets most of the value from dry runs on pull requests, a nightly cold-start and scroll benchmark, and a profile regenerated on every release branch. A large app with many contributors may justify automatic generation and per-merge benchmarks. In every case, the gate measures what users install, and a person, not a single threshold, decides whether a step change blocks the release.

  • A nightly startup median jumps 12 percent once and returns to normal the next night; do you block the release?
    No. A single excursion that disappears on the next run looks like device or environment noise, such as thermal state or background work. Look at the iteration values and that night's trace, and only treat it as a regression if the step persists over consecutive runs or appears on the release candidate's comparison run.
  • Why keep a CompilationMode.None() run next to the Partial(Require) gate?
    The gap between the two medians is what the Baseline Profile is worth to a fresh install. If it shrinks release over release while the gate still passes, the profile is going stale: new startup code is not covered, and it is time to regenerate or extend the journeys.

  • Fail the build whenever one run crosses a fixed millisecond threshold.
  • Run the full benchmark suite on emulators for every pull request.
  • The default compilation mode is the best release gate.
  • Generate the Baseline Profile once, then reuse it for every release.
  • Dry run mode results are good enough for regression tracking.