using-efficient-effects
Installation
SKILL.md
Using Efficient Effects — pick the cheapest correct effect API
Compose ships three effect APIs by default: LaunchedEffect (coroutine, restarts on key change),
DisposableEffect (setup/teardown with a cleanup block), and SideEffect (runs on every successful
composition). The skydoves/compose-effects library adds RememberedEffect — a non-coroutine
analog of LaunchedEffect. Picking the wrong API wastes a coroutine scope, leaks a listener, or
silently drops the latest version of a callback. This skill is the decision tree.
When to use this skill
- The user asks which effect API to choose, or why a
LaunchedEffectrestarts unexpectedly. - A long-lived
LaunchedEffectcalls a stale version of a callback that the parent has updated. - A non-Compose subscriber (listener, observer, broadcast receiver, GL surface) needs setup at composition entry and teardown on key change or exit.
- A composable just needs to react to a key change synchronously and a coroutine scope is overkill.
- A
LazyColumnrow needs its ownViewModelinstance (e.g. one VM per chat row, one VM per feed card) and the parent VM store would leak state across rows. - The user is debugging unexpected effect restarts, leaked listeners, or per-frame allocations from
SideEffect.