<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bagas Pardana Ilham on Medium]]></title>
        <description><![CDATA[Stories by Bagas Pardana Ilham on Medium]]></description>
        <link>https://medium.com/@ilhamp.dev?source=rss-1c9b7e4075d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dp9CLYta4b8QR0cwrJo-Xw.jpeg</url>
            <title>Stories by Bagas Pardana Ilham on Medium</title>
            <link>https://medium.com/@ilhamp.dev?source=rss-1c9b7e4075d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:57:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ilhamp.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Android UI Performance (Part 2): Preserving Object Identity via State Hoisting]]></title>
            <link>https://medium.com/@ilhamp.dev/android-ui-performance-part-2-preserving-object-identity-via-state-hoisting-fc544bf57eec?source=rss-1c9b7e4075d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc544bf57eec</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Bagas Pardana Ilham]]></dc:creator>
            <pubDate>Thu, 16 Jul 2026 11:35:00 GMT</pubDate>
            <atom:updated>2026-07-16T13:29:41.343Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous part, I explored recomposition and also mentioned <strong>Stability</strong> in Jetpack Compose.</p><p><a href="https://medium.com/@ilhamp.dev/android-ui-performance-part-1-exploring-recomposition-stability-39179d53fca0">https://medium.com/@ilhamp.dev/android-ui-performance-part-1-exploring-recomposition-stability-39179d53fca0</a></p><p>But is that already enough to make an app mature in Production? Not quite. Let’s look at why our previous approach has a catch.</p><p>There are some reasons why the previous approach is not efficient:</p><ol><li><strong>Breaking Separation of Concerns</strong>: Putting @Stable or @Immutable annotation (which belong to the Jetpack Compose framework) in the Data Layer will make our code messy and also break the Separation of Concern rule in Clean Architecture. Because we force the Data Layer responsible for how the UI renders the data. The data layer must be 100% neutral from any framework; it shouldn’t know the UI created by XML or Jetpack Compose.</li><li>Using ImmutableList forces us to add an external library and write .toImmutableList() conversion boilerplate everywhere, because standard libraries like Retrofit, Ktor, or Room don&#39;t understand what an ImmutableList is. It creates unnecessary friction across our data pipeline just to please the Compose Compiler.</li><li><strong>Framework Lock-in:</strong> If we decide to migrate some modules to Kotlin Multiplatform (KMP) or another framework in the future, data classes with Compose annotations cannot be reused instantly because they are already tightly coupled with the Jetpack Compose Android library.</li></ol><p>Thankfully, modern Jetpack Compose introduces a game-changing feature enabled by default: <strong>Strong Skipping Mode</strong>.</p><blockquote>Strong Skipping Mode was first introduced as an experimental flag in late 2023 (Compose Compiler 1.5.4). Fast forward to today, it is now <strong>enabled by default</strong> in modern Jetpack Compose (since version 1.7.0)</blockquote><p><strong>Before</strong> this feature existed, the Compose compiler was strict, if a Composable received an “Unstable” parameter like a standard Kotlin List, it would <em>never</em> skip recomposition.</p><p>Strong Skipping Mode changes the rules of the game by introducing a smarter way to evaluate parameters:</p><ol><li><strong>For Stable Types:</strong> It checks the <strong>Content</strong> using Structural Equality (.equals()). <br>If the content is identical -&gt; <strong>Skip Recomposition</strong>.</li><li><strong>For Unstable Types (like standard Lists):</strong> Instead of giving up, it checks the <strong>Object Identity</strong> (the memory address) using Referential Equality (===). <br>If the object is the exact instance in RAM -&gt; <strong>Skip Recomposition</strong>.</li></ol><p>This means, in modern Compose, our main goal shifts: <strong>We no longer need to force class stability through messy annotations. Instead, we just need to ensure our Object Identity (memory address) remains unchanged.</strong></p><p>However, maintaining object identity directly inside the UI layer (using local remember blocks) is a recipe for disaster. Whenever configuration changes happen (ex: screen rotation), this process completely destroys the current Activity and rebuilds the UI from scratch. When this happens, the internal cache of your local remember is wiped out.</p><h4>The Paradigm Shift: Architecture Over Annotations</h4><p>Before Strong Skipping Mode, developers were obsessed with <strong>Data Stability, </strong>forcing @Immutable annotations and wrapping everything in ImmutableList just to make the data stable.</p><p>But now, because Strong Skipping Mode evaluates unstable data types (like standard Kotlin List) using <strong>Referential Equality (</strong><strong>===)</strong>, the game has completely changed:</p><p>The ultimate goal is no longer about making your data classes stable. It is about designing an architecture that preserves the exact same object instance in memory across recompositions.</p><pre>@Composable<br>fun MemoryLeakLabScreen() {<br>    var searchQuery by remember { mutableStateOf(&quot;&quot;) }<br>    val rawProducts by remember { mutableStateOf(loadCoffeeList()) }<br><br>    val filteredProducts = remember {<br>        derivedStateOf {<br>            rawProducts<br>                .filter { it.name.contains(searchQuery, ignoreCase = true) }<br>        }<br>    }<br><br>    val memoryAddress = System.identityHashCode(rawProducts)<br><br>    Log.d(&quot;IdentityTest&quot;, &quot;[UI] Memory Address: $memoryAddress&quot;)<br><br>    Column(<br>        modifier = Modifier<br>            .fillMaxWidth()<br>            .padding(16.dp)<br>    ) {<br>        TextField(<br>            modifier = Modifier.fillMaxWidth(),<br>            value = searchQuery,<br>            onValueChange = { searchQuery = it }<br>        )<br>        Spacer(<br>            modifier = Modifier.height(16.dp)<br>        )<br>        LazyColumn(<br>            modifier = Modifier.fillMaxWidth()<br>        ) {<br>            items(filteredProducts.value) {<br>                Text(text = it.name)<br>            }<br>        }<br>    }<br>}</pre><p>If you use System.identityHashCode() to track your object&#39;s memory address before and after a screen rotation, you will see a clear proof of this flaw:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*vVAwlJ5A3I2CfBuwBgJ8bw.png" /><figcaption>Maintain Object Identity before State Hoisting (1)</figcaption></figure><p>Then rotate the screen, and you can see that the user type is reset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrMRk-cBE_nGX40nx26W0A.png" /><figcaption>Maintain Object Identity before State Hoisting (2)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*cPYWtPK3rG4Pj7G3uTRSAA.png" /><figcaption>Memory Address Log Before &amp; After Screen Rotation</figcaption></figure><p>Because the object identity changes, Strong Skipping Mode loses its reference point. When a rotation happens, the entire UI is destroyed and forced into an Initial Composition. If our data lives inside the UI (remember), it gets wiped out too—forcing the app to re-run expensive data fetching or filtering from scratch, causing a &#39;UI reset&#39; or visual lag for the user.</p><p>This is exactly why <strong>State Hoisting to the ViewModel</strong> transforms from just a clean code design pattern into a vital UI performance strategy. By moving our data states to a lifecycle-aware ViewModel, we lock the object’s identity in a safe vault that survives configuration changes.</p><p>Let’s look at the following implementation.</p><pre>@Composable<br>fun MemoryLeakLabScreen() {<br>    val mainVm: MainViewModel = viewModel()<br>    val filteredProducts by mainVm.filteredProducts.collectAsState()<br>    val searchQuery by mainVm.searchQuery.collectAsState()<br><br>    val memoryAddress = System.identityHashCode(filteredProducts)<br><br>    Log.d(&quot;IdentityTest&quot;, &quot;[UI] Memory Address: $memoryAddress&quot;)<br><br>    Column(<br>        modifier = Modifier<br>            .fillMaxWidth()<br>            .padding(16.dp)<br>    ) {<br>        TextField(<br>            modifier = Modifier.fillMaxWidth(),<br>            value = searchQuery,<br>            onValueChange = {<br>                mainVm.onSearchQueryChanged(it)<br>            }<br>        )<br>        Spacer(<br>            modifier = Modifier.height(16.dp)<br>        )<br>        LazyColumn {<br>            items(filteredProducts) {<br>                Text(text = it.name)<br>            }<br>        }<br>    }<br>}</pre><pre>class MainViewModel: ViewModel() {<br>    private val _searchQuery = MutableStateFlow(&quot;&quot;)<br>    val searchQuery: StateFlow&lt;String&gt; = _searchQuery.asStateFlow()<br><br>    private val rawProducts = loadCoffeeList()<br><br>    val filteredProducts: StateFlow&lt;List&lt;Coffee&gt;&gt; = _searchQuery<br>        .combine(MutableStateFlow(rawProducts)) { query, products -&gt;<br>            if (query.isBlank()) {<br>                products<br>            } else {<br>                products.filter { it.name.contains(query, ignoreCase = true) }<br>            }<br>        }.stateIn(<br>            scope = viewModelScope,<br>            started = SharingStarted.WhileSubscribed(5000),<br>            initialValue = emptyList()<br>        )<br><br>    fun onSearchQueryChanged(newQuery: String) {<br>        _searchQuery.value = newQuery<br>    }<br>}</pre><p>The filteredProducts variable holds a standard Kotlin List&lt;Coffee&gt;, which the compiler technically flags as <strong>Unstable</strong>. In the past, any slight recomposition on this screen would force the LazyColumn to redraw all its items blindly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*hVRXq2A23QwUUqFc6ESJVw.png" /><figcaption>Maintain Object Identity by State Hoisting (1)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QvibhAlFFTokB0QTiHUiuQ.png" /><figcaption>Maintain Object Identity by State Hoisting (2)</figcaption></figure><p>But look closely at our Log.d tracking System.identityHashCode().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*dsZfMvxL1v1IJnUhOsS_1Q.png" /><figcaption>Memory Address Log Before &amp; After Screen Rotation (State Hoisting)</figcaption></figure><p>the memory address of filteredProducts remains strictly identical (===) because it is safely cached inside the ViewModel. Strong Skipping Mode sees this unchanged identity and completely skips redrawing the LazyColumn, saving precious CPU cycles without requiring a single @Immutable annotation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*bB7xWKczk400ITjmdVvNZg.png" /></figure><p>You can also check the following article officially from Android :<br><a href="https://developer.android.com/develop/ui/compose/performance/stability/strongskipping?hl=id">https://developer.android.com/develop/ui/compose/performance/stability/strongskipping?hl=id</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc544bf57eec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android UI Performance (Part 1): Exploring Recomposition & Stability]]></title>
            <link>https://medium.com/@ilhamp.dev/android-ui-performance-part-1-exploring-recomposition-stability-39179d53fca0?source=rss-1c9b7e4075d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/39179d53fca0</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Bagas Pardana Ilham]]></dc:creator>
            <pubDate>Mon, 29 Jun 2026 06:00:33 GMT</pubDate>
            <atom:updated>2026-06-29T06:00:33.582Z</atom:updated>
            <content:encoded><![CDATA[<p>Building a feature in Jetpack Compose is easy. Building a highly optimized, production-ready UI that consumes minimal battery and CPU? That’s where the real engineering begins.</p><p>As Android developers transitioning from the traditional XML View system to declarative UI, we often take Compose’s magic for granted. We change a state, and the UI magically updates. But have you ever wondered what happens under the hood when a single state changes?</p><p>In a complex screen, a small, frequent update (like a timer or a smooth animation) can trigger a domino effect, causing massive, unseen redraws across your entire UI tree. This invisible performance killer is called “<strong>Unnecessary Recomposition”</strong>. The worst part? It won’t show up as a crash in your logs, but your users will feel the lag.</p><p>As a Junior Engineer who tries to truly master this, I created a “Performance Lab” playground app, intentionally broke its stability, and monitored the behavior using the Layout Inspector. In this first part of my Android UI Performance playground series, we will deep dive into how the Compose Compiler determines UI stability and how you can prevent common structural mistakes from dragging down your app’s performance.</p><p><strong>NOTES :</strong></p><ul><li>Recomposition is a normal thing happen to the function that reads a state change. The goal is to keep the visual view on the screen stay update trough related state.</li><li>Our task is not completely eliminate the recomposition across the screen, but to isolate and make other heavy components so that they can skip the Unnecessary Recomposition</li></ul><h4>The Playground Setup: Creating a Controlled Mess</h4><p>I built a simple screen where you have a fast-changing state (like a real-time tracking timer) at the top, and a list of data below it. Visually, the list data never changes, so it shouldn’t redraw itself when the timer ticks, right? Let’s verify that assumption.</p><p>Here is the initial code structure:</p><pre>data class CoffeeItem(<br>    val id: Int,<br>    val name: String,<br>    val isFavorite: Boolean<br>)</pre><pre>@Composable<br>fun PerformanceLabScreen() {<br>    // A simulated real-time tracker changing every second<br>    var timerCount by remember { mutableStateOf(0) }<br>    LaunchedEffect(Unit) {<br>        while (true) {<br>            delay(1000)<br>            timerCount++<br>        }<br>    }<br><br>    val coffeeList = List(10) { id -&gt; <br>        CoffeeItem(id, &quot;Coffee Variant #$id&quot;, false) <br>    }<br><br>    Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {<br>        Text(<br>            text = &quot;App Active Time: $timerCount seconds&quot;,<br>            style = MaterialTheme.typography.headlineSmall<br>        )<br>        <br>        Spacer(modifier = Modifier.height(16.dp))<br>        CoffeeListSection(items = coffeeList)<br>    }<br>}<br><br>@Composable<br>fun CoffeeListSection(items: List&lt;CoffeeItem&gt;) {<br>    LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp)) {<br>        items(items, key = { it.id }) { item -&gt;<br>            CoffeeRow(item = item)<br>        }<br>    }<br>}<br><br>@Composable<br>fun CoffeeRow(item: CoffeeItem) {<br>    Card(modifier = Modifier.fillMaxWidth()) {<br>        Row(modifier = Modifier.padding(16.dp)) {<br>            Text(text = item.name)<br>        }<br>    }<br>}<br></pre><p>At first glance, this code looks perfectly fine. We used a proper LazyColumn and we even provided a stable key for the items.</p><p>But when we fire up the <strong>Android Studio Layout Inspector</strong> and look at the <strong>Recomposition Counts</strong>, the reality hits hard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*3a5dTAX7ET5V7SF0fgk1ww.png" /></figure><ul><li><strong>PerformanceLabScreen</strong>: Recomposing (Expected, due to the timer).</li><li><strong>CoffeeListSection</strong>: Recomposing</li><li><strong>CoffeeRow</strong>: Skipped</li></ul><p>Let’s make the CoffeeRow not skipped from recomposition by update our data model below</p><pre>data class CoffeeItem(<br>    val id: Int,<br>    val name: String,<br>    val isFavorite: Boolean,<br>    val tags: List&lt;String&gt;<br>)</pre><p>Then rerun the app, and you can notice that the CoffeeRow is now recomposing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*mg7ID8FW5U3mVsyg9Rciwg.png" /></figure><p>Why did a simple List&lt;String&gt; can affect our UI performance and break Compose&#39;s ability to skip unchanged components? Let&#39;s talk about <strong>Stability</strong>.</p><p>Compose uses a mechanism called <strong>Smart Optimization (Skipping)</strong>. Before Compose decides to skip a Composable function during recomposition, it asks itself one crucial question:</p><blockquote>“Can I absolutely guarantee that the data passed into this function is <strong>exactly the same</strong> as it was during the previous frame?”</blockquote><p>For primitive data types (Int, String, Boolean, Float), the answer is always <strong>Yes</strong>. Why? Because they are <strong>Immutable</strong> by nature. If an Int changes from 5 to 6, it’s a completely new value. Compose can easily compare oldValue == newValue (structural equality), and if they match, it safely skips the redraw.</p><p>However, for non-primitive data types (specifically collections like java.util.List, Set, or Map), Compose cannot give that guarantee.</p><p>We have two primary solutions to solve this problem: the <strong>Manual Override</strong> and the <strong>Architectural Fix</strong>.</p><h4>a. Solution 1 : The Manual Override (@Immutable or @Stable)</h4><pre>import androidx.compose.runtime.Immutable</pre><pre>@Immutable<br>data class CoffeeItem(<br>    val id: Int,<br>    val name: String,<br>    val isFavorite: Boolean,<br>    val tags: List&lt;String&gt;<br>)</pre><p>By adding the @Immutable annotation, you are signing a strict contract with the Compose Compiler. You are promising that once this CoffeeItem is created, none of its properties—including the items inside the tags list—will ever be mutated.</p><p><strong>The Result:</strong> The compiler stops its defensive play, marks CoffeeItem as stable, and allows CoffeeRow to be <strong>Skipped</strong> successfully in the Layout Inspector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*ERZrI4vgLsLqqTPEbCnNsA.png" /><figcaption>Jetpack Compose Recomposition Test</figcaption></figure><blockquote><strong>WARNING !!</strong></blockquote><blockquote><strong>This is a manual override. If you break your promise and mutate that list in the background anyway, Compose will not detect it, and your UI will fail to update, causing silent visual bugs.</strong></blockquote><h4>b. Solution 2 : The Architectural Fix (ImmutableList) — Highly Recommended</h4><pre>implementation(&quot;org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8&quot;)</pre><p>Then, refactor your data model to use ImmutableList instead of the standard Java/Kotlin List:</p><pre>import kotlinx.collections.immutable.ImmutableList</pre><pre>data class CoffeeItem(<br>    val id: Int,<br>    val name: String,<br>    val isFavorite: Boolean,<br>    val tags: ImmutableList&lt;String&gt; // Compile-time guarantee of stability<br>)</pre><pre>import kotlinx.collections.immutable.toImmutableList</pre><pre>val coffeeList = List(10) { id -&gt; <br>        CoffeeItem(<br>            id = id, <br>            name = &quot;Coffee Variant #$id&quot;, <br>            isFavorite = false, <br>            tags = listOf(&quot;Hot&quot;, &quot;Caffeine&quot;).toImmutableList() // Convert to Immutable<br>        ) <br>    }</pre><p>Result :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*9AK1jd6kI1i97c2WeqG4nA.png" /></figure><ul><li><strong>PerformanceLabScreen</strong>: Recomposing (Normal, updating the timer text).</li><li><strong>CoffeeListSection</strong>: Recomposing (Bad, it should be skipped).</li><li><strong>CoffeeRow</strong>: <strong>SKIPPED</strong> (0 recompositions).</li></ul><p>Unlike the @Immutable annotation,ImmutableList enforces stability at the <strong>compiler level</strong>. Look at the following example, when we forget to add the .<em>toImmutableList</em>() for tags</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*7F5OfHVLsPo2QMD2l4at5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*eUe2CIWsls_p0bOr0f-DoQ.png" /></figure><p>The type system itself prevents anyone from accidentally calling .add() or mutating the collection. The Compose Compiler natively recognizes everything inside kotlinx.collections.immutable as stable by default.</p><p>===============================================================</p><p>Lastly, let’s trace the root cause of why recomposition has happened at <strong>CoffeeListSection</strong>.</p><p>When a @Composable function is recomposed, the compose runtime will re-execute all of the lines of code in that function from top to down. If you write val coffeeList = List(10) { ... } inside a function directly without remember {} , then every time recomposition happens, that line will be re-executed.</p><p>remember act as a <em>cache wrapper</em>. When the code is wrapped by remember, that line will only be executed <strong>once </strong>at <em>Initial Composition</em>.</p><pre>val coffeeList = remember {<br>        List(10) { id -&gt;<br>            CoffeeItem(<br>                id = id,<br>                name = &quot;Coffee Variant #$id&quot;,<br>                isFavorite = false,<br>                tags = listOf(&quot;Hot&quot;, &quot;Caffeine&quot;).toImmutableList()<br>            )<br>        }<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*SadQ9Vb6UxEdJOVoSAt85Q.png" /></figure><p>Ok, you can notice that the CoffeeListSection is now successfully skipped from recomposition.</p><ul><li><strong>PerformanceLabScreen</strong>: Recomposing (Normal, updating the timer text).</li><li><strong>CoffeeListSection</strong>: <strong>SKIPPED</strong> (0 recompositions).</li><li><strong>CoffeeRow</strong>: <strong>SKIPPED</strong> (0 recompositions).</li></ul><p>Great. We have explored a little about recomposition. To make you deeply understand stability and recomposition, you can check the following article by Jaewoong Eum</p><p><a href="https://doveletter.dev/articles/strong-skipping-mode-misconceptions#the-misconception">Strong Skipping Mode in Jetpack Compose: Common Misconceptions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39179d53fca0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>