agentleFS
wrinfotelwrinfotel/verified-android-skills/skills/compose-performance/SKILL.md

compose-performance

Skill0 starsChanged 32 days agoMITView on GitHub

Jetpack Compose performance discipline: stability, recomposition control, deferred state reads, and baseline profiles. Use when writing or reviewing Compose UI code, diagnosing recomposition storms, or preparing release builds. Every rule has a machine check in checks/.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After ANY Compose UI edit, run the Verification step (bottom of this file).

    line 14
  2. Very specific:

    MUST make UI-state data classes fully immutable (val only) and annotate them @Immutable when they are passed as composable parameters.

    line 18
  3. Very specific:

    MUST NOT pass MutableList / MutableMap / MutableSet as composable parameters.

    line 36
  4. Very specific:

    MUST NOT create mutable collections inside remember when the value only feeds the UI.

    line 52
  5. Distinctive:

    MUST defer state reads to the lambda of the modifier or component that needs them, so a changing value skips the parent recomposition.

    line 68
  6. Very specific:

    MUST use derivedStateOf when computing a value from state where only the computed result matters (e.g.

    line 82
  7. Very specific:

    MUST provide a stable, unique key for every items(...) entry whose content or identity changes independently of position.

    line 97
  8. Very specific:

    MUST include a baseline profile for release builds: either a src/main/baseline-prof.txt or the androidx.baselineprofile Gradle plugin wired …

    line 112
  9. Distinctive:

    Run after every Compose-related edit (from the project root):

    line 121
  10. Distinctive:

    All three must pass (exit 0) before declaring the task done.

    line 129

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Compose Performance

Operational rules for a coding agent. RIGHT/WRONG pairs are canonical. After ANY Compose UI edit, run the Verification step (bottom of this file).

1. Stability

MUST make UI-state data classes fully immutable (val only) and annotate them @Immutable when they are passed as composable parameters.

WRONG:

data class UserUi(val name: String, var selected: Boolean)

RIGHT:

@Immutable
data class UserUi(val name: String, val selected: Boolean)

WHY: a single var property makes the class unstable. Every unstable parameter defeats skipping for every composable that receives it, so one mutable field can undo recomposition optimization across a whole screen.

MUST NOT pass MutableList / MutableMap / MutableSet as composable parameters. Use kotlinx.collections.immutable types (ImmutableList, ImmutableMap) or @Immutable wrappers.

WRONG:

@Composable
fun Feed(items: MutableList<String>) { ... }

RIGHT:

@Composable
fun Feed(items: ImmutableList<String>) { ... }

MUST NOT create mutable collections inside remember when the value only feeds the UI. Prefer state-holder classes with immutable snapshots.

WRONG:

val history = remember { mutableListOf<Int>() }

RIGHT:

var history by remember { mutableStateOf(immutableListOf<Int>()) }
// or keep mutation inside a @Stable state-holder that exposes ImmutableList

2. Deferred state reads

MUST defer state reads to the lambda of the modifier or component that needs them, so a changing value skips the parent recomposition.

WRONG:

val offset = scrollState.value
Row(modifier = Modifier.offset(x = offset.dp)) { Header() }

RIGHT:

Row(modifier = Modifier.offset { IntOffset(scrollState.value, 0) }) { Header() }

MUST use derivedStateOf when computing a value from state where only the computed result matters (e.g. "show scroll-to-top button when scrolled").

WRONG:

val showButton = scrollState.value > 0   // recomposes on every pixel

RIGHT:

val showButton by remember { derivedStateOf { scrollState.value > 0 } }

3. Lazy lists

MUST provide a stable, unique key for every items(...) entry whose content or identity changes independently of position.

WRONG:

LazyColumn { items(messages) { msg -> MessageRow(msg) } }

RIGHT:

LazyColumn { items(messages, key = { it.id }) { msg -> MessageRow(msg) } }

4. Baseline profiles

MUST include a baseline profile for release builds: either a src/main/baseline-prof.txt or the androidx.baselineprofile Gradle plugin wired to a macrobenchmark module.

Startup and first-frame jank are dominated by JIT; a baseline profile is the single highest-leverage release setting.

Verification

Run after every Compose-related edit (from the project root):

bash <skill-dir>/checks/check_no_var_in_ui_state.sh  <src-dir>
bash <skill-dir>/checks/check_immutable_collections.sh <src-dir>
bash <skill-dir>/checks/check_baseline_profile.sh    <project-root>

All three must pass (exit 0) before declaring the task done. Checks are deterministic static heuristics — they catch the documented anti-patterns above, not every perf bug. For deep verification use the Compose compiler metrics report and a macrobenchmark, per references/stability.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.