<?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 Nandha Kumar on Medium]]></title>
        <description><![CDATA[Stories by Nandha Kumar on Medium]]></description>
        <link>https://medium.com/@rnandhakumar1995?source=rss-427d1bda35dd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*s6uUoYHrAlkVAlRVVyAWQA.jpeg</url>
            <title>Stories by Nandha Kumar on Medium</title>
            <link>https://medium.com/@rnandhakumar1995?source=rss-427d1bda35dd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:24:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rnandhakumar1995/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[Unlocking Performance: Understanding Strong Skipping in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/unlocking-performance-understanding-strong-skipping-in-jetpack-compose-944fc717e5ed?source=rss-427d1bda35dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/944fc717e5ed</guid>
            <category><![CDATA[recomposition]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Nandha Kumar]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 15:14:00 GMT</pubDate>
            <atom:updated>2024-03-09T16:17:46.458Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered why your composables recompose although no state of the composables has been changed?</p><p>The reason could be unstable parameters being passed into your Composables. But what is unstable parameter? What is the difference between stable and unstable parameters? And, why the compose compiler recomposes composables just for passing unstable parameters? Let’s discuss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DAMWRgrZMeFIw1mq" /><figcaption>Photo by <a href="https://unsplash.com/@chillysheep?utm_source=medium&amp;utm_medium=referral">James Baldwin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Understanding Stable and Unstable Parameters</strong></p><p>A parameter is said to be stable when it is immutable or Compose knows if its value is changed. All primitive data types are stable parameter. Also, data class with all primary constructor’s parameters declared as valis considered stable since parameters values cannot be changed without creating a new object. However, data class with var, collections from util package like List are unstable as those can change at any point in time. Before going any further, we have to understand two concepts which Compose compiler uses to find out whether parameters have been changed: 1. Object equality, that is using Object.equals() which compares values based on object’s equals method, 2. Instance equality, that is comparing two instance for equality using === which compares new instance with previous instance.</p><p><strong>The Magic of Strong Skipping</strong></p><p>The compose compiler marks a restartable composable as skippable if it only has stable parameters. This helps in skipping the recomposition if nothing related to the composable has been changed. Enabling Strong Skipping changes this behaviour by making all restartable composables as skippable by default, thus making skipping more efficient and avoid unwanted recompositions.</p><pre>@Composable<br>fun StrongSkippingScreen(<br>    sampleData: SampleData,<br>) {<br>    var prompt by remember { mutableStateOf(&quot;&quot;) }<br>    Column(<br>        modifier =<br>            Modifier<br>                .padding(all = 8.dp)<br>                .verticalScroll(rememberScrollState()),<br>    ) {<br>        SampleScreen(sampleData)<br>        TextField(<br>            value = prompt,<br>            label = { Text(stringResource(R.string.summarize_label)) },<br>            placeholder = { Text(stringResource(R.string.summarize_hint)) },<br>            onValueChange = { prompt = it },<br>            modifier =<br>            Modifier<br>                .weight(8f),<br>        )<br>    }<br>}<br><br>data class SampleData(var hello: String)</pre><pre>@Composable<br>fun SampleScreen(content: SampleData) {<br>    Text(text = &quot;${content.hello} ${System.currentTimeMillis()}&quot;)<br>}</pre><p>The above SampleScreen composables is non-skippable as theSampleData data class has a mutable parameter content, e.g., when the prompt value changes while typing in the TextField, the above composable will also recomposes even if the same instance of SampleData being passed. If the hello is val , the compose won’t recomposes when prompt changes as it will be considered as a stable parameter.</p><p>If you generate compose compiler report for the SampleScreen composable, it will look as follows. You can see, the composable is restartable but not skippable since it has an unstable parameter, content , which is marked as unstable by the compose compiler.</p><pre>restartable scheme(&quot;[androidx.compose.ui.UiComposable]&quot;) fun SampleScreen(<br>  unstable content: SampleData<br>  unused unstable &lt;this&gt;: MainActivity<br>)</pre><p>To make the composable stable, we can annotate the composable with @Stable . This will tell the compose compiler that this parameter is stable and the compose compiler will be notified when the parameter instance changes.</p><p>To avoid some of these unnecessary recompositions, the concept of Strong Skipping is introduced in Compose compiler in version 1.5.4 as an experimental features and it is in alpha stage. With this compiler option enabled, the compose compiler will compare unstable parameters with instance equality and stable parameters with Object equality. So, the compose compiler will skip recompositions even if an unstable parameter’s value is changed until the parameter object is same as previous, thus making it more performance efficient. After enabling the Strong Skipping option, the compose compiler report for the same composable will become as below</p><pre>restartable skippable scheme(&quot;[androidx.compose.ui.UiComposable]&quot;) fun SampleScreen(<br>  unstable content: SampleData<br>  unused unstable &lt;this&gt;: MainActivity<br>)</pre><p>Now you can see the composable is both skippable and restartable yet the content is unstable. We can still make our composable non-skippable by annotating with @NonSkippableComposable annotation.</p><p><strong>Enabling Strong Skippable</strong></p><p>Though it is still in alpha stage, Adding the following code in app level build.gradle file enables Strong Skipping in theproject with compose compiler 1.5.4.</p><pre>tasks.withType&lt;org.jetbrains.kotlin.gradle.tasks.KotlinCompile&gt; {<br>    compilerOptions.freeCompilerArgs.addAll(<br>        &quot;-P&quot;,<br>        &quot;plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true&quot;,<br>    )<br>}</pre><p>After syncing the gradle, the above SampleScreen composable will not recompose when the prompt state changes.</p><p><strong>Strong Skipping lambdas</strong></p><p>Now, it’s time for Strong Skipping in lambdas. Lambdas with no captures will always be memoised by the Kotlin compiler. Also Lambdas that capture stable values are also memoised by Compose Compiler. With the Strong Skipping enabled, lambdas that capture unstable values are also get memoized.</p><pre>val shouldBeMemoized: () -&gt; Unit = {<br>    Log.i(&quot;SampleScreen&quot;, sampleData.hello)<br>}</pre><p>What it essentially means? Consider, the above lambda function inside a Composable, this captures an unstable key, sampleData. Since, the key was considered unstable, the compose compiler would not memoise the lambda so far. But with Strong Skipping enabled, compose compiler will memoise, by comparing unstable keys using instance equality and stable keys through object equality. Essentially, the above code will become something similar to following code (i.e) the shouldBeMemoized lambda instance will be remembered across multiple recompositions, even if the lambda contains unstable keys.</p><pre>val shouldBeMemoized: () -&gt; Unit = remember(sampleData){<br>  {Log.i(&quot;SampleScreen&quot;, sampleData.hello)}<br>}</pre><p>To avoid memoising, annotate the lambda with@DontMemoize. This will tell the compiler to skip memoization, thus creating new instance of the lambda for every recomposition. This can be useful in some scenarios where we do not want the memoization to happen by the compose compiler.</p><pre>val shouldNotBeMemoized: () -&gt; Unit = @DontMemoize {<br>    Log.i(&quot;SampleScreen&quot;, sampleData.hello)<br>}</pre><p><strong>Conclusion</strong></p><p>Strong Skipping mode relaxes some of the stability rules applied to the composables when it comes to skipping composable functions. Thus making some composables memory efficient and much faster by avoiding unnecessary recompositions. If we can opt-out of Strong Skipping being applied to a composable using @NonSkippableComposable and for lambdas @DontMemoize comes to our rescue. But be cautious while applying these annotations as these may increase number of recompositions of a composable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=944fc717e5ed" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/unlocking-performance-understanding-strong-skipping-in-jetpack-compose-944fc717e5ed">Unlocking Performance: Understanding Strong Skipping in Jetpack Compose</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RecyclerView VS ListView — Unspoken differences and tricks]]></title>
            <link>https://medium.com/@rnandhakumar1995/recyclerview-vs-listview-unspoken-differences-and-tricks-9bbccfae16a0?source=rss-427d1bda35dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bbccfae16a0</guid>
            <category><![CDATA[listview]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tricks]]></category>
            <dc:creator><![CDATA[Nandha Kumar]]></dc:creator>
            <pubDate>Tue, 19 Oct 2021 03:06:39 GMT</pubDate>
            <atom:updated>2021-10-19T03:29:23.221Z</atom:updated>
            <content:encoded><![CDATA[<h3>RecyclerView VS ListView — Unspoken differences and tricks</h3><p>When we think of the <em>differences</em> between ListView and RecyclerView, few things on top of our mind are RecyclerView has various kinds of <em>layout managers</em>, support for item <em>animation</em> and <em>decoration</em>. It <em>recycles</em> views.</p><p>But actually, how can it recycle a view? Isn’t there any other difference other than just recycling?</p><p>I happened to watch a video from Google I/O 2016, in which Google has introduced RecyclerView. I suggest you watch the video.</p><p><a href="https://www.youtube.com/watch?v=LqBlYJTfLP4">https://www.youtube.com/watch?v=LqBlYJTfLP4</a></p><p><strong>Differences</strong></p><p>In ListView, View creation and binding happen in the getView method. Whereas, RecyclerView allows us to separate View creation and data binding.</p><p>In ListView, data is bound to View. In RecyclerView, items are bound to ViewHolder instead of View. The aforementioned helps in making the Views recyclable.</p><p>There will be times when you need to change the list items and update the UI. In ListView, notifyDataSetChanged was used to notify any type of changes in the data. This method will invalidate all the existing items and structures. LayoutManager will rebuild and lay out those views. You cannot target a specific change. There are two types of changes, 1. Item changes (number of items stay the same, but there will be some change in the data) and 2. Structural changes (It includes changes in the number of items like an item is inserted, an item is deleted). RecyclerView allows us to target these changes specifically using different methods.</p><ul><li><a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int)">notifyItemChanged(int)</a></li><li><a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemInserted(int)">notifyItemInserted(int)</a></li><li><a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRemoved(int)">notifyItemRemoved(int)</a></li><li><a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,%20int)">notifyItemRangeChanged(int, int)</a></li><li><a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeInserted(int,%20int)">notifyItemRangeInserted(int, int)</a></li><li><a href="https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeRemoved(int,%20int)">notifyItemRangeRemoved(int, int)</a></li></ul><p>In ListView, we should override getViewTypeCount and return the number of available view types. For this, we have to know the possible view types beforehand. We cannot add view types dynamically. Whereas in RecyclerView, we can have any number of view types. We can directly use layout id as a view type.</p><h4>Tricks</h4><p>Here are some tricks to use RecyclerView efficiently.</p><p>While notifying data change, always use payload. If the payload is empty, RecyclerView merely rebinds the item for the position. If there is any payload, just update the changes to be done.</p><pre>override fun onBindViewHolder(holder: ViewHolder, position: Int, payloads: MutableList&lt;Any&gt;) {<br>    if(payloads.isEmpty()){<br>        onBindViewHolder(holder, position)<br>    }else{<br>        val item = getItem(position)<br>        holder.saved.setValue(!item.isSaved)<br>    }<br>}</pre><p>Always use holder.bindingAdapterPosition to access data. Because when there is any change in the data like insertion or movement, the adapter position will be different from the layout position until the RecyclerView asynchronously calculates the following position.</p><p>Until next time 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bbccfae16a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>