Skip to content

JetBrains/intellij-community / .agents/skills/compose-ui

compose-ui

Verified

Write or audit Compose Desktop UI state, effects, and boundaries.

FileKindSize
OWNERSHIPother20 B
SKILL.mdskill md532 B
architecture/GUIDE.mdmarkdown5.7 KB
architecture/evals/evals.jsonconfig6.5 KB
architecture/references/animation.mdmarkdown11.3 KB
architecture/references/component-api-lists-performance.mdmarkdown4.1 KB
architecture/references/desktop-seams-review-output.mdmarkdown1.5 KB
architecture/references/effects.mdmarkdown1.7 KB
architecture/references/state-boundaries.mdmarkdown5.4 KB
architecture/skill-source.jsonconfig2.0 KB
audit/GUIDE.mdmarkdown14.1 KB
audit/evals/evals.jsonconfig18.1 KB
audit/references/api-hygiene.mdmarkdown8.8 KB
audit/references/audit-search-patterns.mdmarkdown3.9 KB
audit/references/boundary-violations.mdmarkdown3.3 KB
audit/references/effects/derived-state-of-guide.mdmarkdown2.2 KB
audit/references/effects/effect-selection-guide.mdmarkdown2.7 KB
audit/references/effects/infinite-loop-patterns.mdmarkdown2.6 KB
audit/references/effects/overview.mdmarkdown7.7 KB
audit/references/lazy-layouts/animate-item.mdmarkdown2.0 KB
audit/references/lazy-layouts/cache-window-and-prefetch.mdmarkdown3.2 KB
audit/references/lazy-layouts/desktop-scroll-measurement.mdmarkdown2.0 KB
audit/references/lazy-layouts/keys-and-content-type.mdmarkdown2.2 KB
audit/references/lazy-layouts/nested-lazy-layouts.mdmarkdown1.6 KB
audit/references/lazy-layouts/overview.mdmarkdown7.5 KB
audit/references/measurement/benchmarking-methodology.mdmarkdown1.9 KB
audit/references/measurement/overview.mdmarkdown5.5 KB
audit/references/measurement/profiler-setup.mdmarkdown2.5 KB
audit/references/modifiers/custom-modifier-node.mdmarkdown3.4 KB
audit/references/modifiers/modifier-order.mdmarkdown2.1 KB
audit/references/modifiers/overview.mdmarkdown7.4 KB
audit/references/modifiers/phase-deferral.mdmarkdown2.6 KB
audit/references/reporting-guidance.mdmarkdown2.3 KB
audit/references/stability/ci-stability-gate.mdmarkdown2.0 KB
audit/references/stability/desktop-measurement.mdmarkdown2.2 KB
audit/references/stability/overview.mdmarkdown7.6 KB
audit/references/stability/reading-classes-txt.mdmarkdown2.1 KB
audit/references/stability/reading-composables-txt.mdmarkdown1.9 KB
audit/references/stability/stabilising-types.mdmarkdown3.1 KB
audit/references/stability/stability-config-syntax.mdmarkdown1.6 KB
audit/references/stability/stability-inference-algorithm.mdmarkdown3.4 KB
audit/references/stability/strong-skipping-escape-hatches.mdmarkdown2.6 KB
audit/references/subcomposition/desktop-subcomposition-measurement.mdmarkdown1.7 KB
audit/references/subcomposition/overview.mdmarkdown7.2 KB
audit/references/subcomposition/subcomposition-decision-tree.mdmarkdown1.8 KB
audit/references/subcomposition/swing-panel-subcomposition.mdmarkdown1.8 KB
audit/references/tracing-setup.mdmarkdown5.3 KB
audit/references/tracing-usage.mdmarkdown6.3 KB
audit/skill-source.jsonconfig2.5 KB

audit/references/stability/overview.md

View on GitHub
# Compose Stability — Diagnosis and Fix Workflow

Measure before and after every stability optimisation. Do not add `@Stable` or `@Immutable` annotations blindly;
confirm that parameter instability causes a real recomposition problem first.

> **Routing:** Use this workflow when an audit finding points to excessive recompositions due to
> unstable parameters, or when the developer mentions compiler reports, non-skippable composables,
> or type stability.

## Workflow

### Phase 1 — Measure (establish evidence before changing code)

- [ ] **1. Enable Compose Compiler reports.** Add to the module's `build.gradle.kts`:

```kotlin
composeCompiler {
    reportsDestination = layout.buildDirectory.dir("compose_compiler")
    metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
```

- [ ] **2. Build the target variant.**

```bash
./gradlew assemble
```

- [ ] **3. Locate the output files.**

```
build/compose_compiler/
├── <module>_release-classes.txt
├── <module>_release-composables.txt
├── <module>_release-composables.csv
└── <module>_release-module.json
```

For Desktop/JVM builds the suffix may differ; look for the most recent files.

- [ ] **4. Read `composables.txt` first.** Search for `restartable` lines not followed by
  `skippable`; each one is a recomposition entry point that cannot be skipped. Parameter prefixes
  are `stable`, `unstable`, `runtime`, `@static`, and `@dynamic`, and any `unstable` parameter
  blocks skipping.

For the full grammar, read [reading-composables-txt.md](reading-composables-txt.md).

- [ ] **5. Read `classes.txt` to learn *why* a class is unstable.** For every type flagged
  `unstable` in `composables.txt`, find its declaration in `classes.txt`.

For the full grammar, read [reading-classes-txt.md](reading-classes-txt.md).

- [ ] **6. Open `module.json` for triage numbers.** Use counts to compare before/after a fix or
  to decide which module to attack first. Do not treat counts as a KPI.

- [ ] **7. Confirm the problem is real.**

```kotlin
@Composable
fun SuspectItem(data: ItemData) {
    SideEffect { println("SuspectItem recompose: ${data.id}") }
    // ...
}
```

Reproduce the user journey. If the log prints on every scroll tick or animation frame, you have
a real problem.

For Desktop-specific measurement techniques, read [desktop-measurement.md](desktop-measurement.md).

### Phase 2 — Diagnose

- [ ] **8. Prioritise by hot path × frequency.** A recomposition in a `LazyColumn` row beats a
  10× recomposition on a one-off settings screen.

- [ ] **9. Cross-reference with Strong Skipping.** On Kotlin 2.0.20+, Strong Skipping makes every
  restartable composable skippable by default, but unstable params are compared with `===`
  instead of `equals`. A `listOf(...)` allocated fresh every recompose fails `===`.
  Lambdas inside `LazyListScope.items { }` are **not** auto-remembered.

For Strong Skipping edge cases and escape hatches, read
[strong-skipping-escape-hatches.md](strong-skipping-escape-hatches.md).

- [ ] **10. For surprising verdicts (`runtime`, `unknown`), read the inference deep-dive.**

For the algorithm walkthrough, read
[stability-inference-algorithm.md](stability-inference-algorithm.md).

### Phase 3 — Fix

- [ ] **11. Choose the right tier.** Three-tier strategy, in order:

  1. **Restructure** — make the type truly stable (`val` + immutable fields). No annotation needed.
  2. **Annotate** — add `@Immutable` or `@Stable` when you own the source and the contract is
     honoured.
  3. **Configure** — add the type to `stability_config.conf` for third-party or Java types.

For the full stabilisation guide, read [stabilising-types.md](stabilising-types.md).
For the config file grammar, read [stability-config-syntax.md](stability-config-syntax.md).

- [ ] **12. Re-build and re-read the reports.** The previously `unstable` parameter should now
  read `stable` or `runtime`. Re-run the logging test to confirm recompositions dropped.

### Phase 4 — Verify

- [ ] **13. Consider a CI stability gate.** Fails the build when a previously-skippable
  composable becomes non-skippable.

For CI gate setup, read [ci-stability-gate.md](ci-stability-gate.md).

## Patterns

### Do not annotate without evidence

```kotlin
// WRONG — SettingsItem is already inferred stable; @Immutable adds noise
@Immutable
data class SettingsItem(val name: String, val value: Boolean)

// RIGHT — let the compiler infer it
data class SettingsItem(val name: String, val value: Boolean)
```

### `List<T>` parameter blocks skipping

```kotlin
// WRONG — List is an interface; compiler cannot prove immutability
@Composable fun ItemList(items: List<Item>) { /* ... */ }

// RIGHT
@Composable fun ItemList(items: ImmutableList<Item>) { /* ... */ }
```

### Strong Skipping + fresh list literal

```kotlin
// WRONG — listOf allocates fresh every recompose; fails === under Strong Skipping
@Composable fun Header() { ActionRow(actions = listOf(Action.Share, Action.Save)) }

// RIGHT — stable identity
private val HeaderActions = persistentListOf(Action.Share, Action.Save)
@Composable fun Header() { ActionRow(actions = HeaderActions) }
```

### Lambda inside LazyListScope.items is not auto-remembered

```kotlin
// WRONG — lambda in LazyListScope is not auto-remembered
LazyColumn {
    items(snacks, key = { it.id }) { snack ->
        SnackRow(snack, onClick = { vm.select(snack.id) })
    }
}

// RIGHT — method reference is stable
LazyColumn {
    items(snacks, key = { it.id }) { snack ->
        SnackRow(snack, onClick = vm::select)
    }
}
```

## Mandatory rules

- **MUST** measure before optimising. A compiler report alone is not evidence of a real problem.
- **MUST** confirm excessive recompositions with logging or profiling before stabilising a type.
- **MUST NOT** add `@Stable` or `@Immutable` to a type whose contract you cannot guarantee.
- **MUST NOT** target 100% skippability; treat skippability percentages as diagnostic signals for measured frame-time
  regressions.
- **MUST** read `composables.txt` per-parameter annotations, not just the function name.
- **MUST** cross-reference unstable params back to `classes.txt` to identify the root cause.
- **MUST** prefer `@Immutable` over `@Stable` whenever every property is a `val` of an
  already-immutable type.
- **MUST** prefer `kotlinx.collections.immutable` over annotating a mutable collection as stable.
- **MUST NOT** use `listOf()`/`mapOf()`/`setOf()` inside a hot composable body as a parameter.

## Verification checklist

- [ ] `composeCompiler { reportsDestination = ... }` configured and build succeeds.
- [ ] All four report files exist.
- [ ] At least one unstable parameter site identified in `composables.txt`.
- [ ] Each unstable parameter traced back to `classes.txt` for root cause.
- [ ] Logging or profiling confirms excessive recompositions in a hot path.
- [ ] After the fix, the parameter reports `stable` or `runtime`.
- [ ] After the fix, logging confirms recomposition count dropped.
- [ ] No `@Stable`/`@Immutable` added to a type that still contains a `var` or unstable nested type.

## References

- [reading-composables-txt.md](reading-composables-txt.md) — composables.txt grammar
- [reading-classes-txt.md](reading-classes-txt.md) — classes.txt grammar
- [stability-inference-algorithm.md](stability-inference-algorithm.md) — 12-phase algorithm
- [stabilising-types.md](stabilising-types.md) — three-tier waterfall
- [stability-config-syntax.md](stability-config-syntax.md) — config grammar
- [strong-skipping-escape-hatches.md](strong-skipping-escape-hatches.md) — escape hatches
- [desktop-measurement.md](desktop-measurement.md) — Desktop measurement
- [ci-stability-gate.md](ci-stability-gate.md) — CI gate setup
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall