Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosGoogle Cloud Tech: Vibe coding in the pit lane 🏁(23.09.2026 um 01:00 Uhr)
Sichere ProgrammierungBuild an Explainable Vendor-Risk Gate in Node.js(23.09.2026 um 00:27 Uhr)
Sichere ProgrammierungFrom p=none to Enforcement: A Working Sequence for DMARC Rollout(23.09.2026 um 00:40 Uhr)
Sichere ProgrammierungWhen OPA's Bundle Loader Runs Past a `.manifest` Typo(23.09.2026 um 00:53 Uhr)
Sichere ProgrammierungGovernance Attack Surface Review: Bybit(23.09.2026 um 01:00 Uhr)
Linux Tipps & HardeningOpenShot video editor is now available as a snap(23.09.2026 um 00:09 Uhr)
KI & AI VideosAI Revolution: AI Robots Are Beating Humans Now(23.09.2026 um 00:32 Uhr)
YouTube Security VideosGoogle Cloud Tech: Vibe coding in the pit lane 🏁(23.09.2026 um 01:00 Uhr)
Sichere ProgrammierungBuild an Explainable Vendor-Risk Gate in Node.js(23.09.2026 um 00:27 Uhr)
Sichere ProgrammierungFrom p=none to Enforcement: A Working Sequence for DMARC Rollout(23.09.2026 um 00:40 Uhr)
Sichere ProgrammierungWhen OPA's Bundle Loader Runs Past a `.manifest` Typo(23.09.2026 um 00:53 Uhr)
Sichere ProgrammierungGovernance Attack Surface Review: Bybit(23.09.2026 um 01:00 Uhr)
Linux Tipps & HardeningOpenShot video editor is now available as a snap(23.09.2026 um 00:09 Uhr)
KI & AI VideosAI Revolution: AI Robots Are Beating Humans Now(23.09.2026 um 00:32 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Compose Stability and Recomposition Optimization — @Stable/@Immutable/skippable

What You'll Learn This article explains Compose stability (@stable, @Immutable, skippable judgment, Compose Compiler Report, and performance optimization). Understanding Stability Compose skips recomposition if arguments…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




What You'll Learn



This article explains Compose stability (@stable, @Immutable, skippable judgment, Compose Compiler Report, and performance optimization).









Understanding Stability



Compose skips recomposition if arguments haven't changed. Whether skipping is possible depends on the "stability" of the arguments.




// ✅ Stable (auto-detected): primitives, String, function types
@Composable
fun Greeting(name: String) { // String = stable → skippable
Text("Hello, $name")
}

// ❌ Unstable: List, Map and other collections
@Composable
fun UserList(users: List<User>) { // List = unstable → recomposed every time
LazyColumn {
items(users) { UserItem(it) }
}
}












@Immutable






@Immutable
data class User(
val id: String,
val name: String,
val email: String
)

// If all properties are val and stable types, add @Immutable
// Compose treats this class as guaranteed immutable












@stable






@Stable
class CounterState {
var count by mutableIntStateOf(0)
private set

fun increment() { count++ }
}

// @Stable = "As long as equals() returns the same result for the same instance, skipping is possible"
// Use on classes containing MutableState












Stabilizing Collections






// Method 1: kotlinx.collections.immutable
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList

@Composable
fun UserList(users: ImmutableList<User>) { // ✅ Stable
LazyColumn {
items(users.size) { index -> UserItem(users[index]) }
}
}

// Caller side
val users = usersList.toImmutableList()

// Method 2: Wrapper class
@Immutable
data class UserListWrapper(val users: List<User>)












Compose Compiler Report






// build.gradle.kts
android {
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_reports")
metricsDestination = layout.buildDirectory.dir("compose_metrics")
}
}









// Example report output
// app_release-composables.txt
restartable skippable scheme("[androidx.compose.ui.UnitComposable]") fun Greeting(
stable name: String
)

restartable scheme("[androidx.compose.ui.UnitComposable]") fun UserList(
unstable users: List<User> // ← Unstable! Not skippable
)












derivedStateOf






@Composable
fun FilteredList(items: List<Item>, query: String) {
// ❌ Recomputed every time
val filtered = items.filter { it.name.contains(query) }

// ✅ Recomputed only when result changes
val filtered by remember(items, query) {
derivedStateOf { items.filter { it.name.contains(query) } }
}

LazyColumn {
items(filtered) { item -> ItemRow(item) }
}
}












Stabilization with key






@Composable
fun ItemList(items: List<Item>) {
LazyColumn {
items(
items = items,
key = { it.id } // ✅ key guarantees identity → reused
) { item ->
ItemRow(item)
}
}
}












remember + lambda stabilization






// ❌ New lambda instance created every time
@Composable
fun Parent(viewModel: MyViewModel) {
Child(onClick = { viewModel.doSomething() })
}

// ✅ remember stabilizes lambda
@Composable
fun Parent(viewModel: MyViewModel) {
val onClick = remember(viewModel) { { viewModel.doSomething() } }
Child(onClick = onClick)
}












Summary




































Technique Use Case
@Immutable Immutable data classes
@Stable Classes with MutableState
ImmutableList Stabilize collections
derivedStateOf Optimize derived state
key LazyList item identity
Compiler Report Discover unstable args



  • Use Compose Compiler Report to find unstable arguments

  • Mark stability with @Immutable/@Stable

  • Stabilize collections with kotlinx.collections.immutable

  • Prevent unnecessary recalculation with derivedStateOf






8 production-ready Android app templates (performance optimized) are available.



Browse templatesGumroad



Related articles:




  • Recomposition debugging

  • LazyColumn optimization

  • Baseline Profile









Ready-Made Android App Templates



8 production-ready Android app templates with Jetpack Compose, MVVM, Hilt, and Material 3.



Browse templatesGumroad

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Compose Stability and Recomposition Optimization — @Stable/@Immutable/skippable

Thematisch verwandte Begriffe: Compose, Stability, Recomposition, Optimization · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-58268 | SIPGO is a library for writing SIP services in the GO language. Prior to…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick