compose-performance

A set of rules for making Jetpack Compose screens update efficiently. It covers how Compose decides when to redraw parts of a screen, how to track changing inputs, and how to control remembered values and background effects.

In plain words
What is it for?
Use it when tuning Compose performance, writing scrolling lists, managing remembered state, adding previews, or creating screenshot tests.
Why use it?
It helps avoid unnecessary screen updates and prevents effects or cached calculations from using stale inputs. It also addresses cases where lists or data types are hard for Compose to track safely.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/roninforge/roninforge-kotlin-compose/compose-performance
Clone the repo
git clone --depth 1 https://github.com/RoninForge/roninforge-kotlin-compose
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,091 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01091
Opus 5 $0.00000 $0.00545
Sonnet 5 $0.00000 $0.00218
Haiku 4.5 $0.00000 $0.00109

Measured 2d ago against content hash a2fdadfddaef, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

compose-performance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/compose-performance.mdc · 152 lines

How it starts

The opening of the file, as written. The whole thing — 152 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Compose Performance

Strong skipping (Kotlin 2.x default)

Since Compose Compiler ships with Kotlin 2.0+, strong-skipping is on by default. Most composables skip recomposition for unstable parameters automatically. Stability annotations matter less than they did, but still help in two cases:

  • Data classes the compiler cannot prove immutable (because a parameter is from another module).
  • Collections (List<T>, Map<K, V>) which are unstable even when contents are immutable - mark wrappers with @Immutable.
@Immutable
data class UserCard(
    val id: String,
    val name: String,
    val tags: List<String>,
)

@Stable says: "I will notify Compose when I mutate." @Immutable says: "I never mutate."

Recomposition keys

The key list of LaunchedEffect, remember, produceState, DisposableEffect controls when the block re-runs. Always pass the actual dependencies; never true or Unit as a shortcut.

// BAD - never re-runs even when userId changes
LaunchedEffect(true) { vm.load(userId) }

// CORRECT
LaunchedEffect(userId) { vm.load(userId) }

remember with multiple keys

// Re-compute only when input or filter changes
val filtered = remember(items, filter) {
    items.filter { it.matches(filter) }
}

derivedStateOf for cheap reads on expensive state

val showFab by remember {
    derivedStateOf { listState.firstVisibleItemIndex > 0 }
}

derivedStateOf reduces recomposition triggers by deriving a smaller surface from a larger state. Use when many composables read a coarse state but most do not care about every change.

Deferred reads with lambda parameters

// BAD - reads state at the calling composable's recomposition scope
@Composable
fun BadList(items: List<Item>) {
    items.forEach { Row(item = it) }
}

// CORRECT - lambda defers the read into Row's scope
@Composable
fun GoodList(itemsProvider: () -> List<Item>) {
    val items = itemsProvider()
    LazyColumn { items(items, key = { it.id }) { Row(item = it) } }
}

Read the full file on GitHub · 152 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 152 lines · 0 tokens per session scan A a2fdadfddaef

Subscribe to this mod's changes

compose-performance is a cursor rule published in the GitHub repository RoninForge/roninforge-kotlin-compose (1 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,091 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.