# Measure startup, jank & leaks

Source: https://olef.dev/docs/guides/measure-performance

**Outcome:** quantify startup latency, frame drops, unnecessary Compose recompositions, or retained memory objects before and after a code change—without dumping huge HPROF files.

## Prerequisites

`perf frames` and `perf startup` run from the host against any installed app. `perf leaks` and `layout recompositions --why` require a debuggable app (and supported Compose 1.13+ metadata for `--why`). Always compare numbers on the same device or emulator; an emulator number reflects that emulator, not a budget physical phone.

## Ask your agent

```text
Measure cold startup and scroll jank on the Feed screen before and after my
change using Olef. Then navigate into Detail and back three times and run
`olef perf leaks` to check for retained Activities, Fragments, or ViewModels.
```

## 1. Verified cold, warm, and hot startup

Mixing cold and warm launches makes fake regressions and fake speedups easy to invent. `olef perf startup` verifies the Android `LaunchState` for every iteration and captures `reportFullyDrawn()` when your app emits it:

```bash
olef perf startup --app com.example.app --mode cold --iterations 5
olef perf startup --app com.example.app --mode warm --iterations 5
```

## 2. Frame jank budgets

Reset `gfxinfo framestats`, exercise the scrolling or animation interaction, then sample percentiles (`p50`, `p90`, `p95`, `p99`), janky-frame counts, and software-rendering attribution:

```bash
olef perf frames reset --app com.example.app
# Scroll or animate the screen under test
olef ui swipe-ext up --scale 0.7
olef perf frames sample --app com.example.app
```

## 3. Bounded JVMTI leak chains (no HPROF dump)

After navigating through a screen and popping back (or rotating), scan for retained destroyed Activities, Fragments, detached Views, and cleared ViewModels:

```bash
olef perf leaks --app com.example.app
```

`perf leaks` runs a time- and pause-capped JVMTI heap walk inside the debuggable process and returns shortest GC-root retention paths directly as structured JSON.

## 4. Find *why* Compose recomposed

Knowing a composable recomposed is half the answer; knowing what state read triggered it tells the agent what to fix:

```bash
olef --project-root . layout recompositions --app com.example.app --why
```

## Limits

- `perf leaks` is a bounded diagnostic walk designed to stay responsive; it surfaces common Android lifecycle leaks rather than acting as a full heap profiler.
- Emulator frame timings are useful for relative before/after comparisons, not absolute production SLAs. For representative hardware measurements, run on a USB phone or lease a physical device via [Cloud emulators & real phones](https://olef.dev/docs/cloud/devices).

See [`olef perf`](https://olef.dev/docs/reference/cli/perf) and [`olef layout`](https://olef.dev/docs/reference/cli/layout) for all flags and budget options.
