Skip to content

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

compose-ui

Verified

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

FileKindSize
OWNERSHIPother20 B
SKILL.mdskill md637 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/measurement/overview.md

View on GitHub
# Compose Desktop Measurement — Choose the Right Tool

Record a baseline before applying a change, then measure the delta afterward. Never commit a performance fix without
numbers showing the before/after improvement.

> **Routing:** Use this workflow before and after any performance optimisation to establish a
> baseline and verify improvement. Also use when the symptom is "it's slow" but no specific
> cause is identified yet.

## Workflow

### Phase 1 — Choose the tool

Match the symptom to the tool:

| Symptom | Primary tool | Secondary tool |
|---------|-------------|----------------|
| High CPU at rest | JFR / YourKit CPU sampling | SideEffect logging |
| Jank during scroll/animation | JFR / YourKit | SideEffect logging per composable |
| Memory growth / OOM | YourKit heap dump / JFR heap | `Runtime.getRuntime()` logging |
| Recompositions without jank | SideEffect logging | Compose tracing runtime |
| Slow startup | JFR startup recording | YourKit CPU sampling |
| Window resize lag | JFR during resize | Subcomposition logging |

For detailed tool setup, read [profiler-setup.md](profiler-setup.md).

### Phase 2 — Establish baseline

- [ ] **1. Define the scenario.** Write down the exact steps:
  - Start the app.
  - Navigate to screen X.
  - Scroll to item Y.
  - Perform action Z.

- [ ] **2. Warm up the JVM.** Run the scenario once to let JIT compile hot paths.

- [ ] **3. Record the baseline.**

For CPU:

```bash
# Pass JVM flags via JAVA_TOOL_OPTIONS — --args are application arguments, not JVM arguments
JAVA_TOOL_OPTIONS="-XX:+FlightRecorder -XX:StartFlightRecording=duration=60s,filename=baseline.jfr" \
  ./gradlew run
```

For logging:

```kotlin
SideEffect { println("[Baseline] ${composableName} recomposed at ${System.currentTimeMillis()}") }
```

For memory:

```kotlin
val runtime = Runtime.getRuntime()
println("[Baseline] used: ${(runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024} MB")
```

- [ ] **4. Quantify the baseline.** Extract one number:
  - CPU: % time in `ComposerKt` or target call stack.
  - Recompositions: count per scenario.
  - Memory: MB retained after GC.
  - Frame time: ms between `withFrameNanos` ticks (approximate).

### Phase 3 — Apply change

- [ ] **5. Make the minimum targeted change.** One fix at a time. Do not combine multiple
  optimisations — you will not know which one worked.

### Phase 4 — Measure delta

- [ ] **6. Re-run the exact same scenario.**

- [ ] **7. Compute delta.**

```
Improvement % = (baseline - after) / baseline * 100
```

- [ ] **8. Decide.**
  - If improvement is > 10% and statistically consistent, keep the change.
  - If improvement is < 5% or noisy, revert and try a different approach.
  - If the change causes a regression, revert immediately.

For statistical rigour, read [benchmarking-methodology.md](benchmarking-methodology.md).

### Phase 5 — Document

- [ ] **9. Add a comment.** Explain why the optimisation exists and what the baseline number was.

```kotlin
// Optimisation: hoisted list literal to prevent === failure under Strong Skipping.
// Baseline: 47 recompositions per scroll. After: 3 recompositions per scroll.
private val StaticActions = persistentListOf(Action.Share, Action.Save)
```

## Patterns

### SideEffect recomposition counter

```kotlin
@Composable
fun MeasuredComposable() {
    SideEffect { println("[Recompose] ${this::class.simpleName} at ${System.currentTimeMillis()}") }
    // ...
}
```

### withFrameNanos frame-time approximation

```kotlin
LaunchedEffect(Unit) {
    var lastFrame = 0L
    while (isActive) {
        val now = withFrameNanos { it }
        if (lastFrame != 0L) {
            val deltaMs = (now - lastFrame) / 1_000_000
            if (deltaMs > 17) println("[Frame] dropped: ${deltaMs}ms")
        }
        lastFrame = now
    }
}
```

Gaps > 17ms at 60Hz or > 8ms at 120Hz indicate missed frames.

### Memory snapshot before/after

```kotlin
// Must be called from a background coroutine — never from the main/EDT thread.
suspend fun logMemory(tag: String) = withContext(Dispatchers.IO) {
    System.gc()
    delay(100) // let GC settle
    val runtime = Runtime.getRuntime()
    val used = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024
    println("[Memory] $tag: ${used}MB")
}
```

Call before and after the scenario from a `LaunchedEffect` or a background coroutine.

## Mandatory rules

- **MUST** establish a reproducible baseline before any performance change.
- **MUST** change one thing at a time.
- **MUST** measure in a warmed-up JVM. Cold-start numbers are misleading.
- **MUST** verify on a release-mode build or equivalent (no debug instrumentation) before
  concluding. Debug builds lie: JIT tiers, assertions, and extra allocations skew numbers.
- **MUST NOT** commit a performance fix without before/after numbers in the PR description or a
  code comment.
- **MUST** prefer JFR for initial broad profiling — it is built into the JDK.
- **MUST** use YourKit when JFR is insufficient (heap analysis, allocation tracking).

## Verification checklist

- [ ] A reproducible scenario is documented (steps, data, duration).
- [ ] Baseline numbers were captured before the change.
- [ ] Post-change numbers were captured by running the identical scenario.
- [ ] Delta is calculated and documented.
- [ ] The change is kept only if improvement is >10% and consistent across repeated runs.
- [ ] No regression in unrelated metrics.

## References

- [profiler-setup.md](profiler-setup.md) — JFR, YourKit, async-profiler installation and configuration
- [benchmarking-methodology.md](benchmarking-methodology.md) — sample size, variance, common pitfalls
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: 472kUpdated 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: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated 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