<?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 Jaewoong Eum on Medium]]></title>
        <description><![CDATA[Stories by Jaewoong Eum on Medium]]></description>
        <link>https://medium.com/@skydoves?source=rss-9bb203a4ab2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*to22-X47VSP4tZeElwVKKA.png</url>
            <title>Stories by Jaewoong Eum on Medium</title>
            <link>https://medium.com/@skydoves?source=rss-9bb203a4ab2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 17:05:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@skydoves/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[Announcing Jetpack Compose Mechanisms: The Book and Course on How Compose Actually Works]]></title>
            <link>https://skydoves.medium.com/announcing-jetpack-compose-mechanisms-the-book-and-course-on-how-compose-actually-works-23f5c29016a9?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/23f5c29016a9</guid>
            <category><![CDATA[android-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[compose-ui]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sun, 21 Jun 2026 01:38:50 GMT</pubDate>
            <atom:updated>2026-06-21T01:38:50.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtscZM9Y2pZ9Iipg8biSrg.png" /></figure><p>You hit a recomposition that made no sense. You opened the function, read it twice, and still could not see why it ran again. Maybe you added a remember, shuffled a parameter, and it went away, and you never learned why. Every Compose developer has lived some version of that moment. This post is about the question you quietly moved past: what is actually happening under that @Composable function?</p><p>In this article, you’ll look at three of those puzzles up close, the function that is not the function you wrote, a value that survives by position, and a screen that looks clean while it burns frames. Then you’ll see what the book built to answer them covers across its four parts, and how the companion course turns that reading into practice.</p><h3>The gap between using and understanding</h3><p>Most developers know how to use Compose. Far fewer know what runs underneath a @Composable function, and that gap stays invisible until the day a screen recomposes more than it should, a type refuses to skip, or a list drops frames during a scroll. At that point the usual advice runs out, and you are left guessing at a system you cannot see.</p><p>Here is the kind of thing worth being able to see. You write this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24487ffb0b09b137a227ad928968b886/href">https://medium.com/media/24487ffb0b09b137a227ad928968b886/href</a></iframe><p>The compiler rewrites the signature to fun Greeting(name: String, $composer: Composer?, $changed: Int), wraps the body in a restart group, and adds a skip check that can bypass the entire function when name has not changed since the last composition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lWTWd2H162YrSy9ByV6EWA.png" /></figure><p>Every part of that rewrite has a reason. Once you can read the output, recomposition stops being something that happens to you and becomes something you can trace.</p><h3>Where does a remembered value actually go?</h3><p>You call remember { mutableStateOf(0) } dozens of times a day and trust that the value comes back. But where does it actually go? Not into a variable, not into a map, not into a field on your composable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6aa8065dea93696c4a4bb2e7bbb27ee/href">https://medium.com/media/c6aa8065dea93696c4a4bb2e7bbb27ee/href</a></iframe><p>Because remember is inline, it never opens a group or a call frame of its own. It folds into a single call to $composer.cache(...), and the value disappears into a flat array called the slot table. On the next composition the runtime walks that array with a cursor and hands your value back by its position alone, with no key and no lookup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*QicMqkKpicK7lGsQGegb9g.png" /></figure><p>That one design choice, identity by position, explains a surprising amount of everyday Compose behavior:</p><ul><li>The value survives recomposition because its slot stays at the same position.</li><li>It is lost on a configuration change because the slot table is destroyed and rebuilt from scratch.</li><li>It is discarded the moment you move that remember inside an if whose branch stops running, because the slot only lives as long as its group does.</li></ul><p>A plain var cannot do any of this. It has no slot, so it resets every time the function runs. remember does, and the book traces the whole path: the lowering that turns remember into $composer.cache(false), the rememberedValue() that reads the next slot and the updateRememberedValue() that writes it back, and the gap buffer that makes advancing to the next slot a single cursor move. Once you have seen it, positional memoization stops being a rule you follow and becomes a mechanism you can reason about.</p><h3>How many problems can you spot?</h3><p>Reading the compiler and the runtime is not academic. It is what lets you look at ordinary code and see the frames it will cost. Here is a chat screen written the way most of us would write it first. It compiles, it works, and at a glance nothing looks wrong: a data class with every field a val, a LazyColumn over the messages, and a few lambdas wired to a ViewModel. Before you read on, take a moment with it and count how many problems you can find.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e29e7c3daa99d51a6c1b1d7cac97070/href">https://medium.com/media/3e29e7c3daa99d51a6c1b1d7cac97070/href</a></iframe><p>Did you find them? There are five, and each one traces to a layer this book takes apart:</p><ol><li><strong>An unstable </strong><strong>data class.</strong> ChatMessage holds a List&lt;Reaction&gt; and a List&lt;Attachment&gt;, and because List is an interface that a MutableList can hide behind, the compiler marks the whole class unstable. That single verdict weakens every skip check MessageBubble would otherwise get.</li><li><strong>State read at the wrong scope.</strong> messages and currentUser are both read at the top of ChatScreen, so a change to either recomposes the entire screen instead of the one row that changed.</li><li><strong>No keys on the list.</strong> The LazyColumn gives its items no key, so they are identified by position. Insert or reorder a message and Compose matches rows to the wrong slots, recomposing items that did not change.</li><li><strong>A fresh lambda per row.</strong> onReply and onReact capture each row&#39;s message, so they are rebuilt as the list updates, and a new lambda identity defeats the child&#39;s skip check.</li><li><strong>The ViewModel captured in every row.</strong> Those same lambdas also close over viewModel, so every row carries its own captured handler instead of sharing one stable reference.</li></ol><p>If your first reaction is that strong skipping already takes care of the first one, that is the most common misconception about Compose performance since strong skipping became the default in Kotlin 2.0.20. Strong skipping does not make List stable. It lets a composable with an unstable parameter skip, but only by comparing that parameter with reference equality (===) instead of equals(). So MessageBubble skips when the exact same ChatMessage instance comes through again, and recomposes the moment a new one arrives. A ViewModel that rebuilds its state with copy() or maps it through a Flow hands down a fresh instance on every emission, structurally identical and referentially new, so the === check fails and the row recomposes anyway. Strong skipping raised the floor. It did not remove the need to understand stability completely, and telling those two cases apart is exactly the kind of distinction the book makes precise.</p><p>None of these surface in a code review, because the code is correct. They surface as dropped frames. The fixes are small and specific: an immutable collection for the first, a key on the list for the third, scoped reads and method references for the rest. The book&#39;s final chapter applies each one to this exact screen and takes it from 47 recompositions per second during a scroll down to near zero. The goal of reading is not to memorize that checklist. It is that by the end you see these the moment you write them, because you understand the compiler, runtime, and UI machinery that turns each one into wasted frames.</p><h3>The questions the book answers</h3><p>You just met three of these puzzles: a function that is not the function you wrote, a value that survives by position, and a screen that looks clean while it burns frames. Each one has a precise answer, and collecting those answers is why I wrote this book.</p><p>I wrote it because I wanted more developers to see the logic underneath Compose, the part that still feels like magic from the outside. And that machinery does not hold still. Compose’s internals change constantly. Every new Kotlin release reshapes the Compose compiler, the IR and FIR backends and the lowering passes that run on them, so the internals have shifted year after year since the first release. A lot of what you find written about them describes a version of Compose that has already moved on.</p><p>So the book is built from primary sources. Every mechanism in it comes from reading the AOSP source directly, one piece at a time, not from summaries of it. It is also grounded in tools I built and shipped around these same internals, including <a href="https://github.com/skydoves/compose-stability-analyzer">Compose Stability Analyzer</a>, <a href="https://github.com/skydoves/compose-stability-inference">Compose Stability Inference</a>, <a href="https://github.com/skydoves/compose-nav-graph/">Compose Navigation Graph</a>, <a href="https://hotswan.dev/">Compose HotSwan</a>, and <a href="https://github.com/skydoves/compose-performance-skills">Compose Performance Skills</a>. The explanations describe code I have used, debugged, and depended on in production, down to the Composer and the Compose runtime themselves.</p><h3>What the book covers</h3><p>The book follows Compose in the order the machine runs, from the compiler down to the pixels on screen, in four parts.</p><h4>Part 1: The Compose Compiler</h4><p>This is where your code stops being yours. You’ll see why @Composable changes a function&#39;s type as deeply as suspend does, and why that one fact decides where you can and cannot call it. You&#39;ll follow the $composer and $changed parameters the compiler injects into every signature, the stability inference that decides whether a single List field marks an entire class unstable, and the lambda memoization that keeps your event handlers from breaking skipping. All of it is a sequence of IR passes you can read, and by the end you can predict the exact code the compiler writes in place of yours.</p><h4>Part 2: The Compose Runtime</h4><p>This is where state lives. You’ll see the slot table built on a gap buffer, the same structure a text editor uses to make edits at the cursor cheap, and why that is what lets remember find your value by position alone. You&#39;ll trace the snapshot system and its MVCC isolation, the reason mutableStateOf notifies the composition while a plain var changes nothing, and the recomposition scheduler that decides what runs again and when. The part closes on the Applier, the one seam that makes the entire runtime indifferent to whether the tree is Android UI, a vector image, or the markers on a map.</p><h4>Part 3: The Compose UI</h4><p>This is where nodes become pixels. You’ll see why modifier order is structure rather than styling, how the modifier and coordinator chains turn a list of modifiers into measurement and drawing, and why Compose measures the whole tree in a single pass where the View system took two. You’ll follow the rendering pipeline and its graphics layers, input and gesture dispatch, focus, and the parallel semantics tree that screen readers and tests actually read. The part ends by building a miniature working Compose UI from scratch, which is the clearest proof that the runtime does not care what the tree is.</p><h4>Part 4: Performance, where it all comes together</h4><p>The last part is the synthesis, and the most practical one. It takes the compiler’s stability inference, the runtime’s skip decision, and the UI layer’s rendering phases and turns them into one model you use to answer a single working question: what actually runs each frame, and how do you make it run less? You’ll scope state reads to the right phase, stabilize the types and lambdas that quietly defeat skipping, read compiler reports and system traces, and return to the chat screen from earlier until those 47 recompositions per second become near zero. By the end, the compiler, the runtime, and the UI stop being three separate topics and become the way you reason about a real performance problem in your own app.</p><h3>Who it’s for</h3><p>The book assumes you can already build with Compose and want to know what happens when you do. You do not need compiler or systems experience to start, and you do not need to read every section in order. Each part opens with concepts any Compose developer can follow and goes deeper from there, so where you stop is up to you. Within that, it is written with a few readers in mind:</p><ul><li><strong>Intermediate Compose developers</strong> comfortable with remember, mutableStateOf, and LaunchedEffect who want to understand why those APIs behave the way they do.</li><li><strong>Senior engineers</strong> who want the full picture: the IR pipeline, the snapshot design, the slot table layout, and the single-pass measurement architecture.</li><li><strong>Library and SDK authors</strong> who need the modifier system, the Applier, and SubcomposeLayout to build components that integrate correctly with measurement and rendering.</li></ul><h3>The course: from understanding to practice</h3><p>Unlike passive reading, the <a href="https://doveletter.dev/course/compose">Jetpack Compose Mechanisms course</a> challenges you to actively engage with the material through <strong>240+ interactive assessments</strong> and <strong>120+ practical questions with full answers</strong>, plus 59 follow-up challenges across 8 chapters. Whether you’re debugging recomposition, building a custom layout, or chasing frame drops, learn to reason about Compose’s mechanisms with clarity, curiosity, and confidence.</p><h3>Where to start</h3><p>Jetpack Compose Mechanisms is available now as a book at <a href="https://www.howcomposeworks.com/en">howcomposeworks.com</a>. If you want to read it and stop there, it stands on its own.</p><p>If you would rather practice as you learn, the <a href="https://doveletter.dev/course/compose">written course</a> turns the same material into an interactive path. It is built on the book but is not a copy of it: it runs about 1.5 times longer with fuller explanations, and its assessments, step-by-step walkthroughs, and their answers are written for the course edition and are not in the book. You work through real scenarios, test yourself as you go, and earn a certificate when you finish. The book gives you the understanding, and the course is where you make it stick.</p><p>If you have ever opened a @Composable function and wondered what was happening under there, this is that answer, worked out line by line. Once you can see the machinery, Compose stops being a set of APIs to memorize and becomes a system you can reason about from first principles.</p><p>As always, happy coding!</p><p>— <a href="https://github.com/skydoves/">Jaewoong (skydoves)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23f5c29016a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose Hot Reload on Real Android Devices: Reduce the Build Time to Seconds]]></title>
            <link>https://proandroiddev.com/jetpack-compose-hot-reload-on-real-android-devices-with-compose-hotswan-2f5dfccd55bf?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f5dfccd55bf</guid>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[hot-reloading]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Tue, 31 Mar 2026 02:51:42 GMT</pubDate>
            <atom:updated>2026-04-04T17:42:53.920Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0yvyGd2-xT2xeU-8" /><figcaption>Upsplash@lenaborge</figcaption></figure><p>In Jetpack Compose development, you are probably rebuilding your app tens of times per day to adjust the subtle design specifications. Each rebuild takes anywhere from 1 min to several minutes (~30 mins depending on your project scale), followed by navigating back to the screen you were working on and reconstructing the state you just lost for fair self-testing.</p><p>Let’s be honest. That adds up to one to two hours of dead time per day, every day, spent waiting instead of iterating. Well, for some, it’s the perfect coffee break. For others, it’s a frustrating blocker that slows everything down. That’s exactly the problem Compose HotSwan is built to solve.</p><p><a href="https://hotswan.dev/">Compose HotSwan</a> is a JetBrains IDE plugin for Android Studio/IntelliJ and a Gradle compiler plugin that performs Jetpack Compose hot reload on real physical Android devices/emulators, applying code changes to a running app in one to three seconds with full state preservation as possible.</p><p>In this article, you will explore what you can do with Compose HotSwan, the engineering constraints that make hot reload on Android difficult, how Compose HotSwan works within those constraints, and its core capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhGY3fyxOcZRsgmx_q5Vdw.gif" /></figure><h3>The build tax: What slow feedback actually costs you</h3><p>Every Android developer knows the routine. You tweak a modifier, hit run, and wait. The build compiles, dexes, installs, and restarts your app. It launches from the home screen. You tap through multiple screens, scroll to the right position, and recreate the state just to see a one-line change.</p><p>This is not just an inconvenience. It changes how you make decisions, and the cost compounds throughout your day.</p><p>Picture this. You are working on a screen buried several layers deep. Everything is set up exactly where you need it. You change fontSize = 16.sp to 18.sp. Gradle starts building. On a small project, it takes a minute. On a large codebase, it takes much longer. The app reinstalls and restarts from the “home screen”.</p><p>All your state is gone. Now you navigate back again. Load the data again. Scroll to the same spot again. And when you finally get there, you cannot remember what the previous state looked like. The context you built up is gone after a single build cycle.</p><p>Now you do it all over again. And by the time you get back, you have already forgotten what you were comparing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*sIQFIaFD-9jG4eiA9Qy-7A.gif" /></figure><p>With hot reload, this entire loop collapses. You change a value, save the file, and see the result on your device in ~1 second, with the same screen, the same state, and the same scroll position still in place. The video below shows this in practice: modifying composable code and watching the running app update in real time without a rebuild or restart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJKvhDbLh6ckxatAAepj_Q.gif" /></figure><p>When you save a file, it compiles only the changed code via Gradle’s incremental build, extracts the modified classes from the resulting DEX, transfers them to the device, and swaps them directly in ART’s memory using a native agent. It then triggers a scoped recomposition that invalidates only the affected composable scopes while preserving the slot table structures and all embedded state.</p><p>It sounds like a compelling shift in how you build with Compose, right? But on Android, this is fundamentally harder due to ART’s strict runtime constraints, which make class swapping far more restrictive than on other platforms. The engineering behind Compose HotSwan is covered later in this article.</p><h3>Installation and setup</h3><p>Getting Compose HotSwan running takes three primary steps: install the IDE plugin, apply the Gradle plugin, and sync.</p><h4>Requirements</h4><p>Make sure your environment meets these prerequisites. Your project’s minSdk does not matter for Compose HotSwan. What matters is the API level of the device you are running on. API 30 or higher is recommended because it supports a broader range of reloadable changes, including new functions, enum values, and data class properties.</p><p>For the full requirements and Gradle configuration options, see the <a href="https://hotswan.dev/docs/requirements">Requirements</a> and <a href="https://hotswan.dev/docs/gradle">Gradle Configuration</a> documentation.</p><h4>Step 1: Install the IDE plugin</h4><p>Open Android Studio (Meerkat 2024.3 or later) and navigate to Settings &gt; Plugins &gt; Marketplace. Search for &quot;Compose HotSwan&quot; and install it. Restart the IDE when prompted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XiHjUTb6_32tI1tY" /></figure><h4>Step 2: Apply the Gradle plugin</h4><p>Add the HotSwan compiler plugin to your version catalog. In libs.versions.toml:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdb6b0e77248d055736c130403b27d91/href">https://medium.com/media/cdb6b0e77248d055736c130403b27d91/href</a></iframe><p>For the recent version, check out the official <a href="https://hotswan.dev/releases">release notes</a> docs.</p><h4>Step 3: Sync and run</h4><p>Sync Gradle, build your app in debug mode, and run your app on your physical device or emulator. Once the app is running, hit the “Start HotSwan” button and wait a second. Now, you are ready to hot reload. Make a change to any Compose file, save it, and watch the update appear on your device in seconds.</p><h4>1 more step: Get the Free License</h4><p>Compose HotSwan is a freemium plugin, and you can start a 2-week free trial with full access to all features. This gives you plenty of time to try it in your own project and experience the impact firsthand.</p><p>You can claim your free trial in under 10 seconds by clicking the button in the Compose HotSwan panel with your JetBrains account. <a href="https://hotswan.dev/pricing">As for pricing</a>, well, it’s not about the price. It’s about your time. Save hours every day writing Compose.</p><h3>What you can hot reload</h3><p>The scope of reloadable changes directly determines how much of your daily workflow benefits from hot reload. If a tool only handles color and text changes, it helps with a narrow slice of UI iteration. Compose HotSwan covers a broader range because the compiler plugin and native client SDK operate at the class level, not the composable level.</p><p><strong>Composable function bodies<br></strong>Any change inside a composable function body reloads instantly. Text, colors, font sizes, layout modifiers, padding, animation parameters, conditional logic, and child composable structure all work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79ba91cc108f9f9722a762a911f57c80/href">https://medium.com/media/79ba91cc108f9f9722a762a911f57c80/href</a></iframe><p>Save the file, and the running app updates in place in ~1 second. No rebuild, no reinstall, no navigation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjBaLuN26MD_311IessIJg.gif" /></figure><h4>Adding a new Composable and reordering</h4><p>You can add a new composable function and reorder existing composable calls within a function, and the state follows each composable correctly. Compose HotSwan’s compiler plugin preserves state continuity across structural changes in your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O5A8y8VAJQZUFu-JO2G9kA.gif" /></figure><h4>Non-composable function changes</h4><p>This is one of the key differences from Live Edit, which only supports changes to composable functions. Because Compose HotSwan swaps classes at the ART level, any method body change is reloadable, not just @Composable ones. Changes to ViewModel methods, repository logic, utility functions, and data mappers all hot reload:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0e9e525aa66de697bfa0daa9e10c048/href">https://medium.com/media/a0e9e525aa66de697bfa0daa9e10c048/href</a></iframe><p>Any composable that calls this function displays the updated result on the next recomposition. In practice, this means business logic iteration, not just UI tweaking, benefits from the fast feedback loop.</p><h4>Resource value changes</h4><p>Modify existing values in strings.xml, colors.xml, dimens.xml, and drawable files. HotSwan detects resource file changes and hot reloads all your resource value changes instantly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad67dfd6f5897cfb1c2ba28e56b3a78a/href">https://medium.com/media/ad67dfd6f5897cfb1c2ba28e56b3a78a/href</a></iframe><p>Note that adding entirely new resources (new string keys, new color entries) changes the R class field assignments, requiring a full rebuild. Modifying existing values works because the resource IDs remain unchanged.</p><h4>Data class property additions</h4><p>You can add new properties to data classes, and the toString(), copy(), equals(), and hashCode() methods regenerate automatically:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56e92b9b09a6df7760689941240837cc/href">https://medium.com/media/56e92b9b09a6df7760689941240837cc/href</a></iframe><p>Note that removing properties or changing their types requires a full rebuild. For the complete list of what you can and cannot hot reload, including edge cases around inline functions, lambda count changes, and cross-file references, see the <a href="https://hotswan.dev/docs/supported-changes">Supported Changes</a> documentation.</p><h3>So, how it works: The five-stage pipeline</h3><p>At a high level, Compose HotSwan executes a five-stage pipeline when you save a file: <strong>Save → Compile → Extract → Swap → Recompose</strong>. The IDE detects the changed file, identifies the Gradle module, runs an incremental compilation on just that module, extracts only the modified classes from the resulting DEX, swaps them into the device’s memory via the native ART agent, and triggers a scoped recomposition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*kUNomt755nvkMfX5QOW8Tw.gif" /></figure><p>Each of these five stages contains layers of a waaayyyy more complexity that this summary does not begin to cover. The compilation stage alone involves custom IR transformations, each file compilation, and parameter reservation strategies. The extraction stage performs differential class analysis across lambda renumbering boundaries.</p><p>The swap stage interacts with the Android runtime under constraints that vary by API level. The recomposition stage integrates with the Compose runtime’s slot table through several invalidation strategies. For a more detailed (but still summarized) breakdown of each stage, see the <a href="https://hotswan.dev/docs/how-it-works">How It Works</a> documentation.</p><p>Compose HotSwan targets ART, so its architecture is fundamentally different from JVM-based hot reload and had to be built from scratch in a completely different environment. If you are curious about how hot reload works on the JVM (Desktop) side, the JetBrains team published <a href="https://blog.jetbrains.com/kotlin/2026/01/the-journey-to-compose-hot-reload-1-0-0/">The Journey to Compose Hot Reload 1.0.0</a>, which covers their own path to shipping hot reload for Compose Desktop. Even that article, operating in the comparatively forgiving JVM environment, clearly had to compress an enormous amount of internal detail to fit into a single post.</p><h3>Why hot reload on Android is hard</h3><p>Hot reload on Flutter (Dart VM) and React Native (JavaScript engine) all exist in mature forms. Android is the outlier, and the reason is the runtime itself.</p><h4>This is.. just a research-level problem</h4><p>There is no public API, library, or documented technique for doing this. This is definitely NOT a toy/pet level project. The Kotlin compiler’s internals, ART’s class swapping behavior, the Compose compiler’s code generation patterns, and D8’s DEX output format all intersect in ways that no one has had to reason about jointly before.</p><p>The HotSwan compiler plugin operates at the IR (Intermediate Representation) level of the Kotlin compiler, the same layer where the Compose compiler plugin itself runs. It analyzes function bodies, tracks composable identity, and performs independent compilation so that each function can be swapped in isolation without invalidating unrelated code.</p><p>On the device side, the problem shifts to DEX bytecode. HotSwan performs structural analysis on compiled DEX files, comparing class schemas between the installed APK baseline and the newly compiled output. But “comparing class schemas” understates the complexity. The Kotlin compiler generates synthetic classes for lambdas, and these classes are assigned sequential numeric identifiers. If you add a single lambda in the middle of a file, every subsequent lambda’s class name shifts. It’s a shit.</p><p>The Data class and ViewModel… It&#39;s another headache. Data class modifications require a binary-level schema transformation to reconcile the old memory layout with the new definition. And the Compose compiler generates its own layer of synthetic code, group keys and slot table entries, that track composable identity for recomposition. All of these interact. A change to a composable body can simultaneously trigger lambda renumbering, slot table key changes, and group restructuring, and Compose HotSwan has to handle all of it atomically.</p><h4>The biggest challenge: ART treats class structure as immutable</h4><p>The Android Runtime (ART) performs aggressive optimizations when it loads your app. It compiles bytecode ahead of time, inlines method calls, and lays out objects in memory based on the class definition at load time. Once a class is loaded, ART treats its structure as mostly immutable. You cannot add or remove fields, change method signatures, or alter the class hierarchy at runtime. Only method bodies can be replaced.</p><p>This is a fundamental constraint. A hot reload system for Android must work entirely within these boundaries: detect which changes are safe to swap, and fall back gracefully for everything else.</p><h4>State preservation is a thing; it’s really a matter</h4><p>Hot reload without state preservation is just a faster rebuild tool. You still lose navigation stacks, form data, scroll positions, and all the context you spent time constructing. The time savings from skipping the build are negated by the time spent reconstructing state.</p><p>The real engineering challenge is making the reload invisible: swapping method bodies in memory while keeping the Compose runtime’s slot table intact, so every remember{} value, every scroll position, every dialog state, and every ViewModel instance survives. This requires a compiler plugin that tracks composable identity across reloads and a bunch of multi-tier recomposition strategy that degrades gracefully when targeted invalidation is not possible.</p><h4>Other platforms control their own runtime</h4><p>Flutter runs Dart in the Dart VM. React Native runs JavaScript in Hermes or JSC. Both have full control over class definitions, memory layout, and code loading, which makes hot reload a solvable problem at the VM level. ART is a different kind of runtime. It was designed for production performance: ahead-of-time compilation, aggressive inlining, and fixed memory layouts.</p><p>These are the right trade-offs for shipping apps, but they work against developer iteration. Compose HotSwan does not try to replace ART or work around it. It operates within ART’s constraints, which is what makes the engineering difficult and what makes the result reliable.</p><p>For a deeper look at the full pipeline and the engineering behind each stage, see the <a href="https://hotswan.dev/docs/how-it-works">How It Works</a> documentation.</p><h3>Do the math and save your time</h3><p>To put concrete numbers on this: say you rebuild 30 times per day during active UI work, and each cycle costs you 2 minutes (build + navigate + reconstruct state). That is 60 minutes per day spent waiting. With hot reload completing in 1 to 3 seconds and preserving your full app state, those same 40 iterations take roughly 2 minutes total. That is over an hour reclaimed per day.</p><p>But 2 minutes per build is an optimistic number. It assumes a small to mid-sized project with a warm Gradle daemon. If you work at a large organization where the project has over 1,000 modules, a single incremental build can take 15 to 20 minutes. At that scale, 30 iterations per day is not realistic; developers self-limit to fewer attempts because each one is so expensive.</p><p>Even if you only rebuild 15 times at 15 minutes each, that is nearly 4 hours per day lost to the build cycle. With hot reload, those 15 iterations take under a minute. That is most of a working half-day returned to actual development, every day, for every engineer on the team. Multiply that across a team of 20, and you are looking at hundreds of engineering hours per month.</p><p>When adopted at the team level, hot reload becomes a productivity multiplier for the entire engineering organization. Fewer build cycles means less context switching, faster code reviews with visual proof of changes, tighter designer-developer iteration loops, and shorter time from prototype to production. It is not just about saving minutes per developer. It is a structural improvement to how a development team ships UI work.</p><h3>Conclusion</h3><p><a href="https://hotswan.dev/">Compose HotSwan</a> isn’t built to showcase the technical complexity of hot reload; it’s designed to meaningfully support the Android developer ecosystem and directly improve developer productivity. Going forward, it will continue to focus on helping developers work more efficiently.</p><p>Although not covered in this post, Compose HotSwan also includes several useful features:</p><ul><li><a href="https://hotswan.dev/docs/preview"><strong>Preview Runner</strong></a> that runs your Preview composable in ~1 second on your real device. Then you can generate full, pretty UI docs by running just a single Gradle task. This is a real gem.</li><li><a href="https://hotswan.dev/docs/snapshot"><strong>Screenshot Snapshots</strong></a> that automatically capture screenshots on every hot reload and generate shareable web pages for collaboration with designers</li><li><a href="https://hotswan.dev/docs/mcp-server"><strong>MCP integration</strong></a> that connects with your AI agent to trigger hot reload and supports 20+ MCP tasks.</li></ul><p>Compose HotSwan is available on the <a href="https://plugins.jetbrains.com/plugin/30551-compose-hotswan/">JetBrains Marketplace</a>. The full documentation, including detailed guides for each feature covered in this article, is at <a href="https://hotswan.dev/docs">hotswan.dev/docs</a>. For bug reports and feature requests, file an issue on <a href="https://github.com/skydoves/compose-hotswan-issuetracker">GitHub</a> or join the <a href="https://discord.gg/jaTcyK5XCr">Discord</a>.</p><p>As always, happy coding!</p><p>— <a href="https://github.com/skydoves/">Jaewoong (skydoves)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f5dfccd55bf" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/jetpack-compose-hot-reload-on-real-android-devices-with-compose-hotswan-2f5dfccd55bf">Jetpack Compose Hot Reload on Real Android Devices: Reduce the Build Time to Seconds</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[Build Your Own Landscapist Image Plugin in Jetpack Compose]]></title>
            <link>https://proandroiddev.com/build-your-own-landscapist-image-plugin-in-jetpack-compose-660aecf26236?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/660aecf26236</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sat, 28 Mar 2026 01:23:30 GMT</pubDate>
            <atom:updated>2026-04-04T17:45:37.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gX5bZbcoV4hnr_nZ" /><figcaption>Upsplash@susan_wilkinson</figcaption></figure><p><a href="https://github.com/skydoves/landscapist">Landscapist</a> provides a composable image loading library for Jetpack Compose and Kotlin Multiplatform. Among its image composables, LandscapistImage stands out as the recommended choice: it uses Landscapist&#39;s own standalone loading engine built from scratch for Jetpack Compose and Kotlin Multiplatform, with no dependency on platform-specific loaders like Glide or Coil.</p><p>It handles fetching, caching, decoding, and display internally, and it works identically across Android, iOS, Desktop, and Web. On top of that, LandscapistImage exposes a plugin system through the ImagePlugin sealed interface, giving you five distinct hook points into the image loading lifecycle where you can inject custom behavior without modifying the loader itself.</p><p>In this article, you’ll explore the ImagePlugin architecture, examining each of the five plugin types and why they exist, how ImagePluginComponent collects and dispatches plugins through a DSL, and how built in plugins like <a href="https://skydoves.github.io/landscapist/placeholder/#placeholderplugin">PlaceholderPlugin</a>, <a href="https://skydoves.github.io/landscapist/placeholder/#shimmerplugin">ShimmerPlugin</a>, <a href="https://skydoves.github.io/landscapist/animation/#circular-reveal-animation">CircularRevealPlugin</a>, <a href="https://skydoves.github.io/landscapist/palette/">PalettePlugin</a>, and <a href="https://skydoves.github.io/landscapist/zoomable/#zoomableplugin">ZoomablePlugin</a> implement these interfaces in practice.</p><h3>Why LandscapistImage for plugins</h3><p>Before diving into the plugin system, it is worth understanding why LandscapistImage is the best foundation for plugin based image loading.</p><p>LandscapistImage uses its own standalone engine (landscapist-core) rather than delegating to Glide, Coil, or Fresco. This means every stage of the image loading pipeline, from network fetching through memory caching to bitmap decoding, is controlled by a single Kotlin Multiplatform implementation. The benefit for plugins is direct: when LandscapistImage transitions from loading to success, it knows the exact moment the bitmap becomes available. It passes that bitmap directly to PainterPlugin and SuccessStatePlugin without any adapter layer or platform specific conversion. The plugin receives a real ImageBitmap, not a wrapped platform object.</p><p>This also means LandscapistImage works on every Compose Multiplatform target. A ShimmerPlugin you write for Android runs identically on iOS and Desktop. There is no &quot;this plugin only works with Glide&quot; problem, because there is no Glide in the pipeline.</p><p>If you look at the LandscapistImage composable signature, you can see where plugins fit in:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f838cdb1b2e09159daff35cadf12d4ef/href">https://medium.com/media/f838cdb1b2e09159daff35cadf12d4ef/href</a></iframe><p>The component parameter is the entry point for the plugin system. When you pass a rememberImageComponent { ... } block, every plugin you add inside that block gets dispatched at the correct lifecycle stage automatically. You can still use loading, success, and failure lambdas for one off customization, but plugins are the reusable, composable alternative.</p><h3>The fundamental problem: Extending image loading without modifying it</h3><p>Consider a common scenario: you are loading images with LandscapistImage and want to show a shimmer effect during loading, apply a circular reveal animation on success, and extract the dominant color from the loaded image. Without a plugin system, you would need to manage all of this manually:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb3b1bc8d136d6de5300f3fa4b934119/href">https://medium.com/media/eb3b1bc8d136d6de5300f3fa4b934119/href</a></iframe><p>This approach has two problems. First, each behavior is tightly coupled to the call site. If you want the same shimmer in ten different screens, you duplicate the logic ten times. If you want to add a new behavior, you touch every call site. Second, behaviors that operate at different conceptual layers (UI rendering, painter transformation, side effects) are mixed together in the same lambda, making it harder to reason about what happens when.</p><p>The plugin system solves both problems. It turns each behavior into a self contained, reusable component that declares which lifecycle stage it belongs to. You compose them together declaratively, and the dispatch mechanism handles the rest.</p><h3>Introducing ImagePlugin</h3><p>The ImagePlugin system is designed around one principle: adding or removing image loading behavior should be as simple as adding or removing a single line of code. In practice, that means attaching a plugin with the + operator and detaching it by deleting that line:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3634a29351f3051c1f1fbd18d86f7268/href">https://medium.com/media/3634a29351f3051c1f1fbd18d86f7268/href</a></iframe><p>If the shimmer is no longer needed, you remove the +ShimmerPlugin() line. The rest of the plugins continue to work without any changes. There is no cleanup code, no conditional branches to update, and no shared state to untangle. Each plugin is self contained: it carries its own configuration, renders its own UI or performs its own side effect, and has no dependency on other plugins in the list.</p><p>This makes the plugin system useful beyond pre built options. When your team needs custom behavior tied to the image loading lifecycle, whether that is logging analytics when an image loads, showing a domain specific error screen on failure, or applying a brand specific visual transformation, anyone on the team can implement a custom ImagePlugin, attach it with +, and remove it later if the requirement changes. The plugin boundary keeps custom behavior isolated from the image loading pipeline, so adding or removing a plugin never risks breaking the loader itself.</p><p>The plugin system supports five types of plugins, each targeting a different moment in the image loading lifecycle. Let’s examine the interface that defines them.</p><h3>The ImagePlugin sealed interface</h3><p>The foundation of the plugin system is a sealed interface with five subtypes. Each subtype corresponds to a specific moment in the image loading lifecycle and receives parameters appropriate for that moment. If you examine the ImagePlugin interface:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8522931add9fd6ac4b6fa35d67c77ebe/href">https://medium.com/media/8522931add9fd6ac4b6fa35d67c77ebe/href</a></iframe><p>The remaining three types follow the same pattern:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26b1b58c9d56c47968c077d3293f9c50/href">https://medium.com/media/26b1b58c9d56c47968c077d3293f9c50/href</a></iframe><p>The reason for five separate types rather than a single onStateChanged callback is that each lifecycle stage has fundamentally different needs.</p><p><strong>PainterPlugin</strong> receives the loaded ImageBitmap and the current Painter, and returns a new Painter. This is where you transform the visual output itself. The return type is important: because it takes a Painter in and returns a Painter out, multiple painter plugins can be chained. A circular reveal wraps the original painter, then a blur wraps the reveal, forming a decoration chain. This works because LandscapistImage provides the decoded ImageBitmap directly from its internal cache, so painter plugins always have access to the raw bitmap data for their transformations.</p><p><strong>LoadingStatePlugin</strong> receives the Modifier, ImageOptions, and an executor callback. The executor is a composable lambda that LandscapistImage provides for rendering a low resolution thumbnail while the full image loads. Plugins like ThumbnailPlugin use this executor to request a smaller version of the same image from the loading pipeline. Other loading plugins like ShimmerPlugin ignore the executor entirely and render their own UI instead.</p><p><strong>SuccessStatePlugin</strong> receives the loaded imageBitmap along with the original imageModel. This runs after a successful load, and its primary purpose is side effects rather than UI rendering. The imageModel parameter is included because some side effects, like palette caching, need to associate their results with the original image URL.</p><p><strong>FailureStatePlugin</strong> receives the Throwable reason for the failure. A custom failure plugin could use this to display different error images based on the failure type, for example showing a network error icon for IOException and a format error icon for IllegalArgumentException.</p><p><strong>ComposablePlugin</strong> receives the entire image content as a composable lambda. Unlike the other four types, this plugin does not operate on a specific lifecycle state. Instead, it wraps the rendered image content, regardless of which state produced it. This makes it the right choice for behaviors that apply to the image as a whole, like gesture handling, overlays, or accessibility wrappers.</p><p>The key observation: the sealed interface ensures every plugin must declare which lifecycle stage it belongs to at compile time. There is no ambiguity about when a plugin runs, and the compiler enforces that you implement the correct compose signature for your chosen stage.</p><h3>How plugins are collected: ImagePluginComponent</h3><p>Plugins need a container that collects them and makes them available to the image composable. The ImagePluginComponent class provides a DSL for collecting plugins into an ordered list:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a19edd7497b4de452959af7ecc23808/href">https://medium.com/media/7a19edd7497b4de452959af7ecc23808/href</a></iframe><p>The unaryPlus operator is what enables the +Plugin() syntax. When you write +ShimmerPlugin(), Kotlin invokes the unaryPlus extension function defined inside ImagePluginComponent, which calls add() internally and appends the plugin to the mutable list. Because this is an operator defined in the scope of the component, it only works inside the ImagePluginComponent receiver block, preventing accidental use outside of plugin configuration.</p><p>The rememberImageComponent function creates and remembers this component across recompositions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7681ce3eaa92a84bc8b6925e185f0efa/href">https://medium.com/media/7681ce3eaa92a84bc8b6925e185f0efa/href</a></iframe><p>The remember call ensures the plugin list is built once and cached. This matters for performance: without it, every recomposition would recreate the plugin list and all plugin instances. You use it like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3f0b71a6d8c12c7fa8a1165f68256a1/href">https://medium.com/media/d3f0b71a6d8c12c7fa8a1165f68256a1/href</a></iframe><p>Three plugins, three different lifecycle stages, all composed into a single component with a clean DSL. The order in the block determines the order of execution within each plugin type.</p><h3>Built in plugins: From simple to advanced</h3><p>Now let’s examine how the built in plugins implement these interfaces. Each example demonstrates a different pattern for how plugins interact with LandscapistImage&#39;s loading pipeline.</p><h3><a href="https://skydoves.github.io/landscapist/placeholder/#placeholderplugin">PlaceholderPlugin</a>: The simplest LoadingStatePlugin</h3><p>PlaceholderPlugin is the most straightforward implementation. It displays a static image while loading is in progress, using whatever image source you provide. If you examine the PlaceholderPlugin.Loading class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9055d112c86d5148990704fa82d714f/href">https://medium.com/media/b9055d112c86d5148990704fa82d714f/href</a></iframe><p>The source parameter accepts an ImageBitmap, ImageVector, or Painter. The compose function renders that source using ImageBySource, passing through all the image options from the parent LandscapistImage. This is an important detail: the plugin inherits contentScale, alignment, and other display options automatically, so the placeholder looks consistent with the final image. The apply return pattern means the plugin returns itself, a convention used across all state plugins.</p><p>The failure variant follows the same structure but implements FailureStatePlugin instead:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9294c59b5940d23142e353fa567102f/href">https://medium.com/media/c9294c59b5940d23142e353fa567102f/href</a></iframe><p>Notice how the reason: Throwable? parameter is available but unused here. The built in PlaceholderPlugin.Failure shows the same static image regardless of the error type. A custom failure plugin could inspect this parameter to display different images: a network icon for connection errors, a broken image icon for decode failures, and so on. This is where building your own plugin adds value over the built in options.</p><h3><a href="https://skydoves.github.io/landscapist/placeholder/#shimmerplugin">ShimmerPlugin</a>: Adding animated loading state</h3><p>ShimmerPlugin is another LoadingStatePlugin, but instead of a static image, it displays an animated shimmer effect that signals to the user that content is loading:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e31c2736d2694d3a372fc9b1c4e8650/href">https://medium.com/media/9e31c2736d2694d3a372fc9b1c4e8650/href</a></iframe><p>The structure is identical to PlaceholderPlugin. The only difference is what gets composed. Instead of ImageBySource, it renders a ShimmerContainer with customizable base and highlight colors. This demonstrates how the plugin interface keeps each implementation focused on a single responsibility: PlaceholderPlugin renders a static image, ShimmerPlugin renders an animation, but both hook into the same loading state lifecycle through the same compose signature.</p><p>Also notice that ShimmerPlugin ignores the executor parameter entirely. The executor is there for plugins that want to render a low resolution thumbnail while loading (like ThumbnailPlugin), but ShimmerPlugin has no use for it. This is a benefit of the interface design: plugins receive all the context they might need, but they are free to use only what is relevant to their behavior.</p><h3><a href="https://skydoves.github.io/landscapist/animation/#circular-reveal-animation">CircularRevealPlugin</a>: Transforming the painter</h3><p>CircularRevealPlugin demonstrates the PainterPlugin type, which operates on a fundamentally different level than state plugins. Instead of composing UI at a lifecycle stage, it transforms the Painter that renders the image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f533507b7572b34ab5fc880d6fee7946/href">https://medium.com/media/f533507b7572b34ab5fc880d6fee7946/href</a></iframe><p>The compose function receives the current painter and wraps it with a circular reveal animation painter using rememberCircularRevealPainter. The original painter is passed through as the base, so the animation decorates the existing rendering behavior rather than replacing it. When LandscapistImage first transitions to the success state, the circular reveal painter starts its animation, gradually revealing the image from the center outward.</p><p>The BlurTransformationPlugin follows the same pattern:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d552997e5b403d3ef90b92215ce6e69c/href">https://medium.com/media/d552997e5b403d3ef90b92215ce6e69c/href</a></iframe><p>Both take a painter in and return a new painter out. Because PainterPlugin forms a chain (as shown in the composePainterPlugins dispatch function earlier), you can stack multiple painter transformations. If you add both CircularRevealPlugin and BlurTransformationPlugin, the blur is applied on top of the circular reveal, which wraps the original painter. Reversing the order would produce a different visual result: the reveal would animate over an already blurred image.</p><h3><a href="https://skydoves.github.io/landscapist/palette/">PalettePlugin</a>: Reacting to success with side effects</h3><p>PalettePlugin implements SuccessStatePlugin, running only after the image loads successfully. Unlike the plugins above, PalettePlugin does not render any UI. Its purpose is to extract dominant colors from the loaded bitmap and expose them to the rest of your composable tree:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2984d381b96729c52a9ada4a3f3e21f/href">https://medium.com/media/d2984d381b96729c52a9ada4a3f3e21f/href</a></iframe><p>The compose function triggers the palette generation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d209b6ab6a0cbb5f94e5f93cd544ecf9/href">https://medium.com/media/d209b6ab6a0cbb5f94e5f93cd544ecf9/href</a></iframe><p>This demonstrates that SuccessStatePlugin is not limited to visual rendering. The compose function performs a side effect: generating a color palette from the loaded bitmap and notifying through the paletteLoadedListener. The LocalInspectionMode check skips palette generation during IDE preview, since there is no real bitmap available in preview mode. The useCache flag avoids redundant palette generation when the same image is recomposed without changing.</p><p>Because LandscapistImage provides the imageBitmap directly from its internal decoding pipeline, PalettePlugin does not need to re decode the image or request it from a platform specific API. This is one of the benefits of the standalone engine: the bitmap is already available as a Compose ImageBitmap, ready for analysis.</p><h3><a href="https://skydoves.github.io/landscapist/zoomable/#zoomableplugin">ZoomablePlugin</a>: Wrapping the entire content</h3><p>ZoomablePlugin implements ComposablePlugin, which gives it a different scope than the other four plugin types. Instead of operating on a specific loading state or transforming the painter, it wraps the entire rendered image content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab2345450e88d0e0fec57e9552abaee0/href">https://medium.com/media/ab2345450e88d0e0fec57e9552abaee0/href</a></iframe><p>The content lambda contains whatever LandscapistImage has rendered for the current state, including any modifications from painter plugins. ZoomableContent wraps this content with a gesture detector that handles pinch to zoom, pan, and double tap. The user sees the image and can interact with it without any additional code at the call site.</p><p>The optional state parameter is what makes this plugin particularly useful. If you pass in a ZoomableState from outside, you can read the current zoom level, pan offset, and rotation from other parts of your composable tree. You could display a zoom percentage indicator, add a &quot;reset zoom&quot; button, or synchronize zoom across multiple images. If you do not pass a state, the plugin creates one internally, keeping the simple case simple.</p><p>This is the most flexible plugin type because it has full control over how the image content is presented within the composable hierarchy. You could use ComposablePlugin to add overlays, gesture detectors, context menus, or any other composable wrapper around the image.</p><h3>Putting it all together</h3><p>With all five plugin types available, you can compose a complete image loading experience with LandscapistImage in a few lines:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/960659a4128a010cf15af65baffa7b00/href">https://medium.com/media/960659a4128a010cf15af65baffa7b00/href</a></iframe><p>Each plugin handles one concern. The ShimmerPlugin shows an animated placeholder during loading. The CircularRevealPlugin animates the painter when the image arrives. The PalettePlugin extracts colors after loading. The PlaceholderPlugin.Failure displays an error image on failure. The ZoomablePlugin wraps the entire content with zoom gestures. Five plugins, five different lifecycle hooks, zero manual state management.</p><p>Because the plugin system operates at the Landscapist layer above any specific image loader, the same component configuration also works with GlideImage, CoilImage, and FrescoImage. But LandscapistImage gives you the added benefit of a standalone, multiplatform engine with no third party loader dependency. Your plugins, your loader, and your UI all run from a single Kotlin Multiplatform codebase.</p><p>In this article, you’ve explored the ImagePlugin sealed interface and its five subtypes, how ImagePluginComponent collects plugins through a DSL, and how built in plugins like <a href="https://skydoves.github.io/landscapist/placeholder/#placeholderplugin">PlaceholderPlugin</a>, <a href="https://skydoves.github.io/landscapist/placeholder/#shimmerplugin">ShimmerPlugin</a>, <a href="https://skydoves.github.io/landscapist/animation/#circular-reveal-animation">CircularRevealPlugin</a>, <a href="https://skydoves.github.io/landscapist/palette/">PalettePlugin</a>, and <a href="https://skydoves.github.io/landscapist/zoomable/#zoomableplugin">ZoomablePlugin</a> implement each plugin type in practice.</p><p>Understanding this plugin architecture opens up a wide range of practical use cases. Because each plugin is self contained and attaches with a single + line, you can freely mix and match behaviors for increasingly complex scenarios, a shimmer placeholder combined with a circular reveal and palette extraction, for example, without the complexity scaling with the number of features. When requirements change, you detach a plugin by removing one line and attach a new one in its place.</p><p>As always, happy coding!</p><p>— <a href="https://github.com/skydoves/">Jaewoong (skydoves)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=660aecf26236" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/build-your-own-landscapist-image-plugin-in-jetpack-compose-660aecf26236">Build Your Own Landscapist Image Plugin 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[Practical Kotlin Deep Dive: Master Kotlin Internals and Ace Your Next Technical Interview]]></title>
            <link>https://skydoves.medium.com/practical-kotlin-deep-dive-master-kotlin-internals-and-ace-your-next-technical-interview-33ff30f91493?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/33ff30f91493</guid>
            <category><![CDATA[technical-interview]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 03:55:53 GMT</pubDate>
            <atom:updated>2026-02-18T03:55:53.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ap_pVruZICYLlobnzuo0gg.png" /></figure><p>Most Kotlin developers can write a data class, launch a coroutine, or use lazy without thinking twice. These features work, the code compiles, and the app runs. But there is a gap between knowing how to use Kotlin and understanding what the compiler actually does with your code. That gap is where performance intuition, debugging skill, and technical interview confidence come from. <a href="https://kotlin.skydoves.me/">Practical Kotlin Deep Dive</a> is a book designed to close that gap, covering 70 Kotlin topics across 492 pages with bytecode decompilations, compiler source code references, and KEEP proposal analysis that reveal the machinery behind every feature you use daily.</p><p>In this article, you’ll explore what the book and its companion course cover, walking through each of the six chapters with examples of the insights you’ll find inside. You’ll see how the book approaches topics differently from typical Kotlin resources, what the “Pro Tips for Mastery” sections reveal about internal mechanisms, and how the interactive course format turns that knowledge into verified understanding through Code Playgrounds and 158 quiz questions.</p><h4>Beyond the syntax: Why internals matter</h4><p>Knowing that lazy caches a value on first access is useful. Knowing that the default lazy implementation uses double checked locking with a synchronized block, and that you can switch to a lock free compareAndSet strategy by passing LazyThreadSafetyMode.PUBLICATION, is the difference between using a feature and making informed decisions about it. The same applies across the language. Understanding that every lambda passed to a higher order function creates a Function object on the heap explains why inline exists. Seeing a data class decompiled into seven generated methods explains what the compiler is doing on your behalf.</p><p>This is the approach Practical Kotlin Deep Dive takes throughout. Rather than describing what Kotlin features do, it examines how they work internally, what bytecode they produce, what design trade-offs the language designers made, and what the KEEP proposals reveal about the reasoning behind those decisions. The goal is not academic. It is practical: when you understand the internals, you write better code, you debug faster, and you answer technical interview questions with the depth that distinguishes senior engineers.</p><h3>What the book covers: Six chapters, 70 topics</h3><p>The book is organized into six chapters, each focusing on a distinct area of Kotlin development. Every chapter contains deep dive explanations, real code examples, and “Pro Tips for Mastery” sections that uncover what happens beneath the surface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*kDUArUeF08GkKnzvSj9OjQ.png" /></figure><h4>Chapter 1: Kotlin Language (24 topics)</h4><p>The first chapter covers the language fundamentals that every Kotlin developer works with daily: null safety, the type system, classes and inheritance, sealed classes, generics, inline functions, delegation, and more. But instead of stopping at usage patterns, each topic traces the feature back to its design origins.</p><p>For example, the null safety section does not just explain the ?. safe call operator. It examines how the Kotlin compiler inserts Intrinsics.checkNotNullParameter calls at every function boundary for non nullable parameters, creating a runtime safety net that catches null violations the moment they cross a type boundary rather than letting them propagate silently through your code. The data class section decompiles a single line data class User(val name: String, val age: Int) into the full Java equivalent, revealing the constructor with null checks, componentN() methods for destructuring, the synthetic copy$default method with bitmask based default parameter handling, and content based equals(), hashCode(), and toString() implementations.</p><p>Throughout this chapter, you’ll find references to KEEP proposals and JetBrains YouTrack discussions that explain why the language was designed the way it is, not just what it does.</p><h4>Chapter 2: Standard Library (7 topics)</h4><p>The standard library chapter explores the collections framework, sequences, scope functions, and the utilities that make Kotlin code concise and expressive. The focus here is on understanding the internal differences that affect performance and correctness.</p><p>One key insight is the distinction between listOf() and emptyList() at the implementation level. While listOf() with no arguments returns the same singleton empty list as emptyList(), the two functions take different paths through the standard library. Understanding these paths, along with the difference between eager collection operations and lazy Sequence evaluation, helps you make the right choice in performance sensitive contexts. The scope functions section (let, run, apply, also, with) goes beyond the typical &quot;use let for null checks&quot; advice, examining how these functions compile and when the inline keyword eliminates their overhead entirely.</p><h4>Chapter 3: Coroutines (19 topics)</h4><p>The coroutines chapter is the largest in the book, reflecting the depth and complexity of Kotlin’s approach to asynchronous programming. It covers suspending functions, coroutine builders (launch, async, runBlocking), structured concurrency, CoroutineScope, dispatchers, Job and SupervisorJob, exception handling, Flow, StateFlow, SharedFlow, channels, and more.</p><p>What sets this chapter apart is the internal analysis. The section on CancellationException is a good example. Most developers know that cancellation in coroutines uses exceptions, but the book traces exactly how CancellationException propagates through the coroutine hierarchy, why it receives special treatment compared to other exceptions, and what happens when you accidentally catch it with a broad catch (e: Exception) block. This is the kind of subtle detail that causes real bugs in production and comes up frequently in technical interviews.</p><p>The Flow sections examine the cold stream model, the internal buffering strategies of SharedFlow, and the difference between stateIn and shareIn at the implementation level. If you have ever wondered why StateFlow always requires an initial value while SharedFlow does not, this chapter explains the architectural reason.</p><h4>Chapter 4: KotlinX Libraries (4 topics)</h4><p>This chapter covers the official Kotlin extension libraries: kotlinx-serialization, kotlinx-datetime, kotlinx-collections-immutable, and kotlinx-io. These are the libraries that JetBrains maintains as part of the broader Kotlin ecosystem, and understanding their internals helps you use them more effectively.</p><p>The kotlinx-serialization section is particularly revealing. Unlike reflection based serialization libraries like Gson or Jackson, kotlinx-serialization uses a compiler plugin to generate serializer classes at compile time. The book walks through what the @Serializable annotation triggers in the compilation pipeline, how the generated KSerializer implementation works, and why this approach delivers better performance and full multiplatform support compared to reflection based alternatives.</p><h4>Chapter 5: Kotlin Compiler and Plugins (7 topics)</h4><p>This chapter takes you behind the compilation process itself. It covers the compiler’s architecture, the difference between KAPT and KSP for annotation processing, the K2 compiler with its new FIR (Frontend Intermediate Representation), the IR (Intermediate Representation) backend, and how compiler plugins like Compose and kotlinx-serialization hook into the pipeline.</p><p>The KAPT versus KSP comparison is one of the most practical sections. KAPT works by generating Java stubs from Kotlin source files and then running standard Java annotation processors on those stubs. This means KAPT essentially performs a partial compilation twice, which is why it significantly impacts build times. KSP, by contrast, directly accesses Kotlin’s compiler symbols without generating stubs, making it 2x or more faster in many projects. The book explains exactly where this performance difference comes from and helps you evaluate when migrating from KAPT to KSP is worth the effort.</p><h4>Chapter 6: Kotlin Multiplatform (9 topics)</h4><p>The final chapter covers Kotlin Multiplatform (KMP), including project structure, source set hierarchies, the expect/actual mechanism for platform specific APIs, interoperability with Swift and Objective C, and Compose Multiplatform for shared UI development.</p><p>The expect/actual section demonstrates how KMP solves the fundamental challenge of cross platform development: writing shared code that needs to behave differently on each platform. The book shows how expect declarations serve as compile time contracts that platform specific modules must fulfill, how the compiler verifies that every expect has a corresponding actual for each target, and why this approach provides better safety guarantees than runtime polymorphism. You&#39;ll see concrete examples of shared modules calling platform specific APIs for Android (Log.d), iOS (NSLog), and JVM (println), all through a single shared interface.</p><h4>Pro Tips for Mastery: The depth that differentiates</h4><p>Throughout the book, you’ll encounter “Pro Tips for Mastery” sections marked with a distinctive callout. These sections go deeper than the main content, diving into bytecode decompilations, compiler source code, and implementation details that most Kotlin resources never touch.</p><p>The book contains over 50 of these Pro Tips. Some examples:</p><ul><li><strong>Value class erasure and boxing boundaries</strong>: How the compiler erases value class wrappers in the generated bytecode, and exactly which situations (generic contexts, nullable types, storing as Any) force the compiler to &quot;box&quot; the value into a real heap allocated object.</li><li><strong>Lazy delegate thread safety internals</strong>: The three distinct implementations behind lazy() (UnsafeLazyImpl, SynchronizedLazyImpl, SafePublicationLazyImpl) and the concurrency trade-offs each one makes.</li><li><strong>Extension function compilation</strong>: How every extension function compiles to a static method on the JVM, with the receiver passed as the first parameter, and why this means extensions use static dispatch rather than polymorphic dispatch.</li><li><strong>Higher order function allocation cost</strong>: How every lambda creates a Function object on the heap, and how inline eliminates this by pasting the function and lambda bodies directly at the call site.</li></ul><p>These are the insights that transform how you think about the code you write. They are also the kind of knowledge that distinguishes candidates in technical interviews.</p><h3>The course: Interactive learning with Code Playgrounds</h3><p>The <a href="https://doveletter.skydoves.me/course/kotlin">Practical Kotlin Deep Dive Course</a> is built on top of the same content as the book, with the same ISBN. It adds an interactive layer designed for developers who want to practice and verify their understanding rather than just read about it. You can see what’s inside the course in the What This Course Covers section on <a href="https://doveletter.skydoves.me/course/kotlin">this course page</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/0*JVLPNOvxaRPmWoqw" /></figure><h4>Code Playgrounds</h4><p>Throughout Chapters 1 through 4, each lesson includes a Code Playground section with runnable Kotlin code. These are not isolated exercises. They are directly tied to the concepts covered in the lesson, giving you hands on experience with the exact features you just learned about. Each playground includes key learning objectives, self contained code examples with inline output comments, step by step explanations, and open ended challenges for further exploration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dSHHq_c2PxA43iVN.png" /></figure><h4>158 interactive quiz questions</h4><p>Every chapter concludes with quiz and exercise sections that test your understanding. You get 3 attempts per question, your best score is recorded, and the answer choices are randomized to ensure genuine comprehension rather than memorization. The questions cover both practical knowledge checks and deeper conceptual understanding.</p><h4>Certificate of completion</h4><p>Upon completing all quizzes and exercises with passing scores, you receive a Kotlin Deep Dive Certificate signed by the author. It validates your comprehensive understanding of Kotlin, from language fundamentals to coroutines, compiler internals, and multiplatform development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n69N9FkPLHftsZuG.png" /></figure><h3>Choosing your format</h3><p>Both the book and the course cover the same 70 topics with the same depth. The difference is in how you engage with the material.</p><p>The <strong>book</strong> is available as PDF, EPUB, and print editions (hardcover, paperback, and Kindle) through <a href="https://leanpub.com/kotlin-deep-dive">Leanpub</a>, <a href="https://skydoves.gumroad.com/l/kotlin-deep-dive">Gumroad</a>, and <a href="https://www.amazon.com/dp/B0GGYWB5T5/">Amazon</a>. It works well for developers who prefer reading at their own pace, annotating, and using the content as a reference they can return to. The PDF format is particularly useful for searching specific topics quickly.</p><p><a href="http://leanpub.com/c/leanpub/kotlin-deep-dive-courses/">The <strong>course</strong> ($129 on Leanpub)</a> adds Code Playgrounds, 158 interactive assessments, chapter recaps, a glossary, and a certificate of completion. It is designed for developers who learn better through active practice and want structured verification that they have absorbed the material. The course also supports browser translation for developers who prefer reading in Korean, Japanese, Chinese, Spanish, German, French, Portuguese, and other languages.</p><p>If you want a reference you can search and annotate, choose the book. If you want hands on practice with quizzes and a certificate, choose the course. If you want both, the course includes the full book content.</p><h3>Who this is for</h3><p>Practical Kotlin Deep Dive is written for Kotlin developers who want to move beyond tutorials and understand the language at a deeper level.</p><p><strong>Intermediate developers</strong> will find clear explanations of features they use daily, helping them understand not just how things work but why they were designed that way. <strong>Senior developers</strong> will benefit from the bytecode decompilations, compiler architecture analysis, and KEEP proposal references that provide the depth needed for architectural decisions and code reviews. <strong>Developers preparing for technical interviews</strong> will gain the internal knowledge that distinguishes surface level answers from the kind of in depth responses that demonstrate true mastery.</p><p>Whether you are building Android applications, backend services with Kotlin, or exploring Kotlin Multiplatform for cross platform development, understanding what happens beneath the syntax changes how you write, debug, and reason about your code. The surface level looks the same. The decisions behind it become fundamentally different.</p><p>You can learn more about the book at <a href="https://kotlin.skydoves.me/">kotlin.skydoves.me</a> and explore the course at <a href="https://doveletter.skydoves.me/course/kotlin">doveletter.skydoves.me/course/kotlin</a>.</p><p>As always, happy coding!</p><p>— <a href="https://github.com/skydoves/">Jaewoong (skydoves)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33ff30f91493" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Kotlin Internals You Should Know]]></title>
            <link>https://proandroiddev.com/5-kotlin-internals-you-should-know-d4bab319d4ef?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4bab319d4ef</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[data-class]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 01:29:40 GMT</pubDate>
            <atom:updated>2026-02-17T01:29:40.317Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ajvm9Vx775hD4Tov" /><figcaption>Unsplash@mrsimonfischer</figcaption></figure><p>Kotlin makes writing clean, expressive code feel effortless. Features like data classes, lazy properties, and extension functions save you from the boilerplate that Java developers deal with daily. But behind every concise Kotlin feature is a compiler performing real work, generating bytecode, managing thread safety, and making allocation decisions on your behalf. Understanding what the compiler actually produces helps you write more performant code and make better design decisions.</p><p>In this article, you’ll explore five Kotlin internals that most developers should know, revealing what really happens when the compiler transforms your code. You’ll examine how a single line data class expands into a full suite of generated methods, how the lazy delegate implements three distinct thread safety strategies, how value class achieves zero cost type safety through erasure, how higher order functions create hidden object allocations (and how inline eliminates them), and how extension functions compile to static methods on the JVM.</p><p>These insights originate from <a href="https://kotlin.skydoves.me/">Practical Kotlin Deep Dive</a>, a book that explores 70 Kotlin topics at this level of depth and <a href="https://doveletter.skydoves.me/course/kotlin">The Course: Practical Kotlin Deep Dive</a>, covering the language fundamentals, standard library, coroutines, compiler internals, and Kotlin Multiplatform. Each section below is a window into the kind of “Pro Tips for Mastery” analysis you’ll find throughout the book and course.</p><h4>1. Data class: One line, six generated methods</h4><p>Most developers know that data class auto-generates equals(), hashCode(), and toString(). But the full scope of what the compiler produces from a single line is worth seeing firsthand.</p><p>Start with this Kotlin class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1b28a62953d8d21ec6bb27a95216361/href">https://medium.com/media/b1b28a62953d8d21ec6bb27a95216361/href</a></iframe><p>One line. Two properties. Now look at what the Kotlin compiler generates when this is decompiled into Java bytecode:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9bbcc4370d6da0f974bf53f903967f9/href">https://medium.com/media/a9bbcc4370d6da0f974bf53f903967f9/href</a></iframe><p>The data keyword is an instruction to the compiler to generate a constructor with null safety enforcement via Intrinsics.checkNotNullParameter, componentN() methods that power destructuring declarations (val (name, age) = user), a copy() method plus a synthetic copy$default variant that handles default parameters through a bitmask, and content based toString(), hashCode(), and equals() implementations.</p><p>The key observation: the synthetic copy$default method uses a bitmask to determine which parameters were explicitly provided. The expression (mask &amp; 1) != 0 checks whether the first parameter should use its default (the existing value). This is the same bitmask strategy the Kotlin compiler uses for all default parameters, not just data classes.</p><p>A data class is not magic. It is the Kotlin compiler doing the work more for you, generating the exact boilerplate you would otherwise write by hand in Java.</p><h4>2. Lazy delegate: Three thread safety strategies you choose from</h4><p>The lazy delegate computes a value on first access and caches it. The API is simple: val data: String by lazy { &quot;computed&quot; }. But the internal architecture is far more sophisticated than it appears.</p><p>The entire mechanism is built around the Lazy interface:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56844f01ac153c93dd4346965f63f5aa/href">https://medium.com/media/56844f01ac153c93dd4346965f63f5aa/href</a></iframe><p>All implementations share a common internal strategy. They use a special singleton object called UNINITIALIZED_VALUE as an internal marker. A private _value field starts with this marker. When value is accessed, the implementation checks if _value is still === UNINITIALIZED_VALUE. If it is, the initializer runs. If not, the cached value is returned. After initialization, the reference to the initializer lambda is set to null to allow garbage collection.</p><p>The lazy() factory function returns one of three distinct implementations based on the requested LazyThreadSafetyMode. This is where the design gets interesting.</p><h4>LazyThreadSafetyMode.NONE: UnsafeLazyImpl</h4><p>The simplest and fastest implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77aab2ba06cce75dd614c99bff2a3cac/href">https://medium.com/media/77aab2ba06cce75dd614c99bff2a3cac/href</a></iframe><p>No synchronization. No locks. If two threads access an uninitialized instance simultaneously, the initializer can run twice. Use this only when you can guarantee single threaded access.</p><h4>LazyThreadSafetyMode.SYNCHRONIZED: SynchronizedLazyImpl (the default)</h4><p>The default mode uses double checked locking:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c406e242981db6ef5079233f7aae311/href">https://medium.com/media/2c406e242981db6ef5079233f7aae311/href</a></iframe><p>The first check outside the synchronized block handles the common case (already initialized) without acquiring a lock. The second check inside the lock handles the race condition where another thread initialized the value between the first check and lock acquisition. This is the classic double checked locking pattern, and it guarantees the initializer executes exactly once.</p><h4>LazyThreadSafetyMode.PUBLICATION: SafePublicationLazyImpl</h4><p>The most interesting implementation. It uses a lock free approach with AtomicReferenceFieldUpdater:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3aff9edc41a9459f4fa1012d4d3c9878/href">https://medium.com/media/3aff9edc41a9459f4fa1012d4d3c9878/href</a></iframe><p>Multiple threads can call the initializer concurrently. They all race to set the value via compareAndSet (CAS), an atomic CPU instruction. Only one thread wins. The others discard their computed result and use the winner&#39;s value. This trades potentially redundant computation for lock free concurrency, making it ideal when the initializer is cheap and idempotent.</p><p>Three implementations, three different trade-offs between safety, performance, and concurrency. Most developers use lazy without realizing they are choosing a concurrency strategy.</p><h4>3. Value class: The wrapper that disappears</h4><p>A value class gives you type safety at compile time and zero allocation cost at runtime. The mechanism is erasure: the compiler removes the wrapper class from the generated bytecode wherever possible.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f91afc60d35aaefef74c1f7e50fa2eef/href">https://medium.com/media/f91afc60d35aaefef74c1f7e50fa2eef/href</a></iframe><p>The Kotlin source has a UserId wrapper. The decompiled Java bytecode does not:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/689130d1dc3c190af8cc0f430aedf4d5/href">https://medium.com/media/689130d1dc3c190af8cc0f430aedf4d5/href</a></iframe><p>The processId function signature changed from UserId to String. The UserId(&quot;user-123&quot;) call became a direct String assignment. No heap allocation. The wrapper class has been erased.</p><p>This is the ideal case. But there are situations where the compiler cannot erase the wrapper and must “box” the value into a real object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a40c7181d7d63fae8a9f6cff0970571/href">https://medium.com/media/9a40c7181d7d63fae8a9f6cff0970571/href</a></iframe><p>When a value class is used in a generic context, stored as Any, or used as a nullable type, the compiler must allocate a real object on the heap. The compiler switches between unboxed (primitive) and boxed (object) representations automatically. Understanding when boxing occurs helps you avoid unintentional allocations in performance sensitive code.</p><p>The compiler also mangles function names to prevent signature clashes on the JVM. A function fun UserId.add(other: UserId) compiles to something like public static int add-1bc5(int $this, int other), which is uncallable from Java. This is a deliberate trade-off: Kotlin optimizes for Kotlin callers, and the mangled names prevent ambiguity when multiple value classes wrap the same underlying type.</p><h4>4. Higher-order functions: The hidden cost of lambdas</h4><p>Every time you pass a lambda to a higher-order function, the compiler creates an object. This is the cost most developers never think about.</p><p>Consider this function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae88b61e31f0cdf9e096158083cd4088/href">https://medium.com/media/ae88b61e31f0cdf9e096158083cd4088/href</a></iframe><p>In the generated bytecode, the lambda parameter becomes a Function1 interface:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6351817362ff1b887d38a8604151046/href">https://medium.com/media/a6351817362ff1b887d38a8604151046/href</a></iframe><p>And when you call it with a lambda:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47fbdb719de0efafc1dc8ac3fd4126da/href">https://medium.com/media/47fbdb719de0efafc1dc8ac3fd4126da/href</a></iframe><p>The compiler generates an anonymous class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed1990d0729ac624e7f5062d9ac28b4b/href">https://medium.com/media/ed1990d0729ac624e7f5062d9ac28b4b/href</a></iframe><p>Every call creates a Function1 object on the heap. In a tight loop, this means thousands of small objects being allocated and garbage collected. The overhead includes the object allocation itself, the memory consumption of each Function object, and a virtual method call through invoke() instead of a direct call.</p><p>The inline keyword solves this completely. When a function is marked inline, the compiler pastes both the function body and the lambda body directly at the call site:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab208ee65ed7a66da3e15d2620bd2256/href">https://medium.com/media/ab208ee65ed7a66da3e15d2620bd2256/href</a></iframe><p>This compiles to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be944749b0d99cb9f03d750da3ca95f6/href">https://medium.com/media/be944749b0d99cb9f03d750da3ca95f6/href</a></iframe><p>No Function object. No virtual dispatch. No heap allocation. The lambda body is inlined directly into the call site. This is why the Kotlin standard library marks functions like let, run, apply, also, map, and filter as inline. Without it, every scope function call and every collection transformation would allocate a Function object.</p><p>Understanding this compilation behavior explains why inline exists and when it matters. For functions called infrequently, the allocation overhead is negligible. For functions called in loops or hot paths, inline eliminates a real performance cost.</p><h4>5. Extension functions: Static methods in disguise</h4><p>Extension functions feel like they are adding methods to existing classes. They are not. The compiler transforms every extension function into a static method, passing the receiver as the first parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00d5f7f240fd83c968134cd50da85f7a/href">https://medium.com/media/00d5f7f240fd83c968134cd50da85f7a/href</a></iframe><p>The decompiled Java bytecode reveals the transformation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e58c3826ad5c85dac22919ede940ce6e/href">https://medium.com/media/e58c3826ad5c85dac22919ede940ce6e/href</a></iframe><p>The this inside the extension function is just the first parameter of a static method. The elegant &quot;skydoves&quot;.addExclamation() syntax compiles to ExtensionFunctionKt.addExclamation(&quot;skydoves&quot;).</p><p>This compilation approach has practical consequences:</p><ol><li><strong>No access to private members.</strong> Extension functions cannot access private properties or methods of the class they extend. They are static methods, not actual members of the class.</li><li><strong>No runtime overhead.</strong> The receiver is passed as a standard method argument. There is no reflective lookup, no proxy object, no dynamic dispatch. It is a plain static method call.</li><li><strong>No class modification.</strong> The original class (String in this example) is never altered. This is how Kotlin maintains full backward compatibility while allowing you to &quot;add&quot; methods to classes you do not own, including String, Int, and third party library classes.</li><li><strong>Static dispatch, not polymorphic.</strong> Because extensions are static methods, they are resolved at compile time based on the declared type of the variable, not the runtime type. If you declare a variable as Any and it holds a String, calling an extension defined on String will not work through the Any reference.</li></ol><p>This static method transformation is what makes extension functions both powerful and safe. You get clean syntax without modifying class hierarchies, and the JVM sees nothing unusual, just static method calls.</p><h3>Going deeper</h3><p>These five topics are a small sample of the internal mechanisms covered in <a href="https://kotlin.skydoves.me/">Practical Kotlin Deep Dive</a>. The book explores 70 topics across six chapters, each with the same level of depth you’ve seen here: bytecode decompilations, internal architecture analysis, and references to KEEP proposals and compiler source code. It covers everything from null safety internals and coroutine state machines to the K2 compiler architecture and Kotlin Multiplatform source set hierarchies.</p><p>If you prefer a more interactive learning experience, the <a href="https://doveletter.skydoves.me/course/kotlin">Practical Kotlin Deep Dive Course</a> builds on the same content with 26 lesson hands-on Code Playgrounds, 158 interactive quiz questions, chapter recaps, and a certificate of completion. The course is designed for developers who want to not just read about Kotlin internals, but practice and verify their understanding.</p><p>Whether you choose the book or the course, understanding what happens beneath the syntax transforms how you write Kotlin. You stop guessing about performance characteristics. You make informed decisions about lazy thread safety modes, value class boxing boundaries, and inline placement. The code you write looks the same on the surface, but the reasoning behind it becomes fundamentally different.</p><p>As always, happy coding!</p><p>— <a href="https://github.com/skydoves/">Jaewoong (skydoves)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4bab319d4ef" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/5-kotlin-internals-you-should-know-d4bab319d4ef">5 Kotlin Internals You Should Know</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[Building a Google Maps Style Bottom Sheet with Jetpack Compose]]></title>
            <link>https://proandroiddev.com/building-a-google-maps-style-bottom-sheet-with-jetpack-compose-eccc1f3cf578?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/eccc1f3cf578</guid>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[bottomsheet]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sun, 15 Feb 2026 07:34:23 GMT</pubDate>
            <atom:updated>2026-02-15T17:25:22.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKKTLN9MWK9-YhUm6M_XPA.png" /></figure><p>Google Maps popularized a bottom sheet pattern that most Android developers recognize immediately: a small panel peeking from the bottom of the screen, expandable to a mid height for quick details, and draggable to full screen for comprehensive information. The user interacts with the map behind the sheet at all times. This pattern looks simple on the surface, but implementing it correctly requires solving several problems: multi state anchoring, non modal interaction, dynamic content adaptation, and nested scroll coordination. Jetpack Compose’s standard ModalBottomSheet only supports two states (expanded and hidden) and blocks background interaction with a scrim, making it unsuitable for this use case.</p><p>In this article, you’ll explore how to build a Google Maps style bottom sheet using <a href="https://github.com/skydoves/flexiblebottomsheet">FlexibleBottomSheet</a>, covering how to configure three expansion states with custom height ratios, how to enable non modal mode so users can interact with the content behind the sheet, how to adapt your UI dynamically based on the sheet’s current state, how to control state transitions programmatically, how to handle nested scrolling inside the sheet, and how to wrap content dynamically for variable height sheets.</p><h3>Why ModalBottomSheet falls short</h3><p>Consider the standard Material 3 bottom sheet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a38f40dd78c91260a666308710000ce/href">https://medium.com/media/8a38f40dd78c91260a666308710000ce/href</a></iframe><p>This gives you two states: expanded and hidden. The sheet covers the background with a scrim, blocking all interaction behind it. For a confirmation dialog or action menu, this is fine. But for a Google Maps style experience, you need:</p><ol><li><strong>Three visible states</strong>: A peek height showing a summary, a mid height for details, and a full height for comprehensive content.</li><li><strong>No scrim</strong>: The map behind the sheet must remain fully interactive.</li><li><strong>Dynamic content</strong>: The content should adapt based on the current expansion state.</li><li><strong>Nested scrolling</strong>: Scrollable content inside the fully expanded sheet should scroll naturally, and dragging down from the top of the scroll should collapse the sheet.</li></ol><p><a href="https://github.com/skydoves/flexiblebottomsheet">FlexibleBottomSheet</a> addresses all of these.</p><h4>Setting up a three state bottom sheet</h4><p>The core of the Google Maps pattern is three distinct expansion levels. FlexibleBottomSheet models these with the FlexibleSheetValue enum:</p><ul><li><strong>SlightlyExpanded</strong>: The peek state, a small panel at the bottom showing a summary.</li><li><strong>IntermediatelyExpanded</strong>: The mid height state for quick details.</li><li><strong>FullyExpanded</strong>: The full height state for comprehensive content.</li><li><strong>Hidden</strong>: The sheet is not visible.</li></ul><p>To enable all three visible states, configure rememberFlexibleBottomSheetState with skipSlightlyExpanded = false (it defaults to true) and define size ratios through FlexibleSheetSize:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/493380c71705f0b10a233f32a3e9ae81/href">https://medium.com/media/493380c71705f0b10a233f32a3e9ae81/href</a></iframe><p>Each FlexibleSheetSize value represents a fraction of the screen height. Setting fullyExpanded = 0.9f means the sheet occupies 90% of the screen at full expansion, leaving a sliver of the map visible at the top. Setting slightlyExpanded = 0.18f creates a small peek panel at 18% of the screen.</p><p>The isModal = false flag is what makes this behave like Google Maps. Without it, the sheet renders a scrim over the background and blocks touch events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKKTLN9MWK9-YhUm6M_XPA.png" /></figure><h4>Customizing expansion heights</h4><p>The default FlexibleSheetSize uses ratios of 1.0, 0.5, and 0.25. For a Google Maps-style experience, you&#39;ll want to tune these to match your content.</p><p>A few common configurations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfaf47b5f857191bad06c34b2206d0da/href">https://medium.com/media/dfaf47b5f857191bad06c34b2206d0da/href</a></iframe><p>If you run the above code, it will be like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fd6cDPNCCB4G3Guo_XTAiQ.png" /></figure><p>For the two state configuration, set skipIntermediatelyExpanded = true so the sheet transitions directly between peek and full:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7565089400bb1b5fb350c34fe6d9bab6/href">https://medium.com/media/7565089400bb1b5fb350c34fe6d9bab6/href</a></iframe><p>You can also skip the hidden state entirely with skipHiddenState = true, which keeps the sheet always visible. This is useful when the sheet is a permanent part of the UI, like a map detail panel that can never be fully dismissed.</p><h4>Adapting content based on sheet state</h4><p>Google Maps shows different content at each expansion level: a place name when peeked, photos and ratings when half expanded, and reviews and details when fully expanded. FlexibleBottomSheet supports this through the onTargetChanges callback:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c201a41fe08c90cef3bc2e7cd76b3e68/href">https://medium.com/media/c201a41fe08c90cef3bc2e7cd76b3e68/href</a></iframe><p>The callback fires when targetValue changes, not currentValue. The distinction matters: targetValue represents where the sheet is heading during a drag gesture or animation, while currentValue represents where it was before the gesture started. Using targetValue means the content updates as soon as the user begins dragging toward a new state, creating a responsive feel rather than waiting for the animation to complete.</p><p>You can also use targetValue for more subtle adaptations without swapping entire composables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5de7649add14dcdb85db58ba2a653e26/href">https://medium.com/media/5de7649add14dcdb85db58ba2a653e26/href</a></iframe><p>When peeked, the title truncates to a single line. When expanded, it shows the full text. This pattern is lightweight and avoids layout shifts.</p><h4>Controlling state programmatically</h4><p>Beyond drag gestures, you can control the sheet state programmatically. The FlexibleSheetState provides suspend functions for each transition:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf9173e4d67a80b192c1dee267a93b47/href">https://medium.com/media/cf9173e4d67a80b192c1dee267a93b47/href</a></iframe><p>The show() function is particularly useful. Without a target parameter, it selects the best available state automatically: IntermediatelyExpanded if available, then SlightlyExpanded, then FullyExpanded. You can also pass a specific target:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a7f2dc6f15cea6477b536557843fdc4/href">https://medium.com/media/2a7f2dc6f15cea6477b536557843fdc4/href</a></iframe><p>You can also read the current state to update other parts of your UI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef333e7446107995755acfe253a7f2c8/href">https://medium.com/media/ef333e7446107995755acfe253a7f2c8/href</a></iframe><h4>Vetoing state changes</h4><p>The confirmValueChange callback lets you prevent certain state transitions. For example, to prevent the sheet from being hidden:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cef86ddb2531da890673e24a82da5584/href">https://medium.com/media/cef86ddb2531da890673e24a82da5584/href</a></iframe><p>When the user tries to drag the sheet below the lowest anchor, the gesture is rejected and the sheet snaps back. This is useful for sheets that should always remain visible, similar to skipHiddenState = true but with the flexibility to allow programmatic hiding while blocking gesture based hiding.</p><h4>Handling nested scrolling</h4><p>When you place a LazyColumn or other scrollable content inside the sheet, FlexibleBottomSheet handles the scroll coordination automatically. Dragging up on the list expands the sheet first, and only after the sheet is fully expanded does the list start scrolling:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/680879e9e76f7c82f0ebf62943f8e2e1/href">https://medium.com/media/680879e9e76f7c82f0ebf62943f8e2e1/href</a></iframe><p>The allowNestedScroll parameter (defaulting to true) enables this coordination. When set to false, the inner content scrolls independently and the sheet can only be dragged by the drag handle or areas outside the scrollable content.</p><p>The scroll priority works as follows: dragging up always expands the sheet first. Once fully expanded, upward drag scrolls the list. Dragging down on a non fully expanded sheet collapses it. Dragging down on a fully expanded sheet scrolls the list to the top first, then collapses the sheet.</p><h4>Using wrap content mode</h4><p>Sometimes you don’t want fixed height ratios. For sheets with variable content, FlexibleSheetSize.WrapContent sizes the sheet to fit its content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73ec09ff0c2cc05399052ba3d618819e/href">https://medium.com/media/73ec09ff0c2cc05399052ba3d618819e/href</a></iframe><p>You can mix wrap content with fixed ratios. In this example, the peek and full states size to their content while the intermediate state stays at 50% of the screen. This is useful when the peek state shows a small summary of variable length and the full state shows complete details that vary by item.</p><p>The sheet will never exceed the screen height, even in wrap content mode. If the content is taller than the screen, the sheet caps at full screen height and the content scrolls inside.</p><h4>Setting the initial state</h4><p>By default, the sheet starts in FlexibleSheetValue.Hidden and animates to the first available state. You can change this by setting initialValue:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbd02ffbd7d6f0e1ce051e87d06cd2ed/href">https://medium.com/media/fbd02ffbd7d6f0e1ce051e87d06cd2ed/href</a></iframe><p>The sheet will appear at the peek height immediately, without an entrance animation. This is useful when the sheet is an integral part of the screen rather than a response to a user action.</p><p>The initial value must be consistent with the skip flags. Setting initialValue = FlexibleSheetValue.SlightlyExpanded while skipSlightlyExpanded = true will throw an IllegalArgumentException at composition time, catching the misconfiguration early.</p><h4>Putting it all together</h4><p>Here’s a complete Google Maps style implementation that combines all the concepts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfa8950b382c260dfe1eb9cf6944b669/href">https://medium.com/media/cfa8950b382c260dfe1eb9cf6944b669/href</a></iframe><p>The skipHiddenState = true keeps the sheet always visible, matching Google Maps where the place detail panel can be collapsed but never fully dismissed. The content adapts at each level: a compact header when peeked, action buttons when half expanded, and a full scrollable list of photos, reviews, and information when fully expanded.</p><h4>Conclusion</h4><p>In this article, you’ve explored how to build a Google Maps style multi state bottom sheet using FlexibleBottomSheet. The three key configuration parameters, FlexibleSheetSize for height ratios, isModal = false for background interactivity, and skipSlightlyExpanded = false for enabling the peek state, transform a standard bottom sheet into a flexible, multi stop panel. The onTargetChanges callback enables dynamic content adaptation, making the sheet feel responsive as users drag between states. And features like programmatic state control, nested scroll coordination, and wrap content mode cover the edge cases you&#39;ll encounter in production.</p><p>Whether you’re building a map overlay, a media player with a persistent mini player, a ride sharing app with a collapsible trip panel, or any interface that needs a persistent, multi state panel over interactive content, FlexibleBottomSheet provides the foundation to implement these patterns with minimal configuration and a clean Compose API.</p><p>As always, happy coding!</p><p>— <a href="https://github.com/skydoves/">Jaewoong (skydoves)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eccc1f3cf578" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/building-a-google-maps-style-bottom-sheet-with-jetpack-compose-eccc1f3cf578">Building a Google Maps Style Bottom Sheet with 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[Compose Stability Analyzer 0.7.0: Recomposition Cascade and Live Heatmap]]></title>
            <link>https://proandroiddev.com/compose-stability-analyzer-0-7-0-recomposition-cascade-and-live-heatmap-6e8f789cd8ea?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e8f789cd8ea</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[compose-stability]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sun, 15 Feb 2026 00:08:14 GMT</pubDate>
            <atom:updated>2026-02-15T17:39:38.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lomI8DziVy6AETznAc6dkQ.png" /></figure><p>Jetpack Compose’s stability system determines whether a composable function can be skipped during recomposition. When all parameters are stable, Compose can compare them and skip the function entirely if nothing changed. When even one parameter is unstable, the composable must re-execute every time its parent recomposes. Understanding which composables are stable and which are not is the first step toward optimizing Compose performance, but it’s not the whole picture.</p><p><a href="https://github.com/skydoves/compose-stability-analyzer">Compose Stability Analyzer</a> has been providing real-time stability analysis directly in Android Studio through gutter icons, hover tooltips, inline hints, and code inspections. These features answer the question “is this composable stable?” at a glance. Version 0.7.0 goes further by answering two additional questions that static analysis alone cannot address: “what happens downstream when this composable recomposes?” and “which composables are actually recomposing the most on a real device?”</p><p>In this article, you’ll explore the two new features introduced in version 0.7.0: the <a href="https://skydoves.github.io/compose-stability-analyzer/ide-plugin/recomposition-cascade/">Recomposition Cascade Visualizer</a> and the Live <a href="https://skydoves.github.io/compose-stability-analyzer/ide-plugin/recomposition-heatmap/">Recomposition Heatmap</a>.</p><h3>Live Recomposition Heatmap</h3><p>Static analysis tells you which composables could recompose unnecessarily. The Live Recomposition Heatmap tells you which ones actually are. It bridges runtime behavior with your IDE by reading @TraceRecomposition events from a connected device via ADB and displaying live recomposition counts directly above composable functions in the editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Bs__yCo2gjtlPRZX.gif" /></figure><p>To use the heatmap, you need the Compose Stability Analyzer Gradle plugin applied to your project, composable functions annotated with @TraceRecomposition, and logging enabled via ComposeStabilityAnalyzer.setEnabled(true) in your Application class. With those in place, open the Compose Stability Analyzer tool window and click the Start/Stop button in the title bar. If one device is connected, monitoring begins immediately. If multiple devices are connected, a picker popup lets you choose which one to monitor.</p><p>While the heatmap is running and you interact with your app, recomposition counts appear as color coded annotations above each composable in the editor. Green means fewer than 10 recompositions (normal frequency), yellow means 10 to 50 (worth investigating), and red means more than 50 (likely a performance issue). These thresholds are configurable in Settings &gt; Tools &gt; Compose Stability Analyzer.</p><p>Clicking any heatmap annotation opens the Heatmap tab in the tool window, pre-populated with detailed data for that composable: total recomposition count, recent events listed chronologically, and parameter changes for each event showing which parameters changed, which were stable, and which were unstable. This lets you go from a high level “this composable recomposed 47 times” observation directly to the specific parameter changes that triggered each recomposition, without searching through Logcat manually.</p><p>A clear button in the tool window title bar resets all accumulated data. This is useful when you restart your app or want to measure a specific interaction from a clean state.</p><h3>Recomposition Cascade Visualizer</h3><p>When a composable recomposes, it doesn’t happen in isolation. The function re-executes, which means every child composable it calls also gets invoked. If those children have unstable parameters, they re-execute too, regardless of whether their inputs actually changed. A single unstable composable at the top of your screen can cascade through dozens of downstream functions, each one doing unnecessary work.</p><p>The Recomposition Cascade Visualizer makes this ripple effect visible. Right-click any @Composable function in the editor and select &quot;Analyze Recomposition Cascade.&quot; The plugin traces the call tree from that function downward, building a tree of every composable that would be affected when the root recomposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NT2x7DvhxcmQ54LM.png" /></figure><p>Each node in the tree shows the composable name and its stability status: green for skippable (all parameters stable) and red for non-skippable (at least one unstable parameter). A summary at the top shows aggregate statistics: total downstream composables, how many are skippable, how many are not, and the maximum depth of the tree. This gives you a quick sense of the blast radius. A screen composable with 15 downstream functions and 8 of them non-skippable has a very different performance profile than one with 3 downstream functions that are all skippable.</p><p>The analyzer also handles recursive composable calls. If a tree rendering composable calls itself for child nodes, the cascade visualizer detects the cycle and marks it rather than entering an infinite loop. A configurable depth limit (default: 10 levels) keeps results manageable for deep hierarchies.</p><p>Double-clicking any node in the cascade tree navigates directly to that composable’s source code. This makes the cascade view a practical starting point for performance work: find the non-skippable composables buried deep in your UI tree, jump to their source, and investigate what’s making their parameters unstable.</p><h3>Putting them together</h3><p>The cascade visualizer and the heatmap are complementary. The cascade shows you the theoretical blast radius of a recomposition, the full tree of downstream composables that could be affected. The heatmap shows you the empirical reality, which composables are actually recomposing during real user interactions and how often.</p><p>A practical workflow looks like this: use gutter icons and the Stability Explorer to identify composables with unstable parameters. Run a cascade analysis on your screen-level composables to understand the downstream impact. Then start the heatmap, interact with your app normally, and watch for red annotations. When you spot a hot composable, click its annotation to see the parameter change history. Fix the root cause (make properties val, use immutable collections, add @Stable annotations), clear the heatmap, and repeat your interactions. The counts should drop, confirming that your optimizations are working at runtime, not just in static analysis.</p><p>Both features are available in version 0.7.0 of the Compose Stability Analyzer IntelliJ plugin, which you can install from the JetBrains Marketplace or build from <a href="https://github.com/skydoves/compose-stability-analyzer">the repository</a>.</p><p>As always, happy coding!</p><p>— Jaewoong</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e8f789cd8ea" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/compose-stability-analyzer-0-7-0-recomposition-cascade-and-live-heatmap-6e8f789cd8ea">Compose Stability Analyzer 0.7.0: Recomposition Cascade and Live Heatmap</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[Scalable API Response Handling Across Multi-Layered Architectures with Sandwich]]></title>
            <link>https://proandroiddev.com/scalable-api-response-handling-across-multi-layered-architectures-with-sandwich-39ab02ae8c90?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/39ab02ae8c90</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[retrofit]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 06:25:14 GMT</pubDate>
            <atom:updated>2026-02-09T08:51:08.043Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1XuCOIHxoH7ksL6Z" /><figcaption>Unsplash@picoftasty</figcaption></figure><p>Modern Android applications commonly adopt multi-layered architectures such as MVVM or MVI, where data flows through distinct layers: a data source, a repository, and a ViewModel (or presentation layer). Each layer has a specific responsibility, and network responses must propagate through all of them before reaching the UI. While this separation produces clean, testable code, it introduces a real challenge: how do you handle API responses, including errors and exceptions, as they cross each layer boundary?</p><p>Most developers solve this by wrapping API calls in try-catch blocks and returning fallback values. This works for small projects, but as the number of API calls grows, the approach creates ambiguous results, scattered boilerplate, and lost context that downstream layers need. You end up with ViewModels that cannot tell whether an empty list means &quot;no data&quot; or &quot;network failure,&quot; repositories that swallow important error details, and data sources that repeat the same error handling pattern dozens of times.</p><p>In this article, you’ll explore the problems that emerge when handling Retrofit API calls across layered architectures, why conventional approaches break down at scale, and how <a href="https://github.com/skydoves/sandwich">Sandwich</a> provides a type safe, composable solution that simplifies response handling from the network layer all the way to the UI. You’ll also walk through the full set of Sandwich APIs, from basic response handling to advanced patterns like sequential composition, response merging, global error mapping, and Flow integration, each with real world use cases that show when and why you would reach for them.</p><h4>Retrofit API calls with coroutines</h4><p>Most Android projects use <a href="https://github.com/square/retrofit">Retrofit</a> with <a href="https://github.com/Kotlin/kotlinx.coroutines">Kotlin coroutines</a> for network communication. A typical service interface looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebcba33386d664d1cf69a89234d2e22a/href">https://medium.com/media/ebcba33386d664d1cf69a89234d2e22a/href</a></iframe><p>The service returns a List&lt;Poster&gt; directly. Retrofit deserializes the JSON response body and gives you the data. This works perfectly when the request succeeds, but it gives you no structured way to handle failures. Retrofit throws an HttpException for non 2xx status codes and various IO exceptions for network problems. The responsibility of catching these falls entirely on the caller.</p><p>When you consume this service in a data source, the conventional approach looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/845c154be94a17386e9f7b1b9a6d0ad3/href">https://medium.com/media/845c154be94a17386e9f7b1b9a6d0ad3/href</a></iframe><p>The data source catches every possible exception and returns emptyList() as a fallback. From the caller&#39;s perspective, this function always succeeds, it always returns a List&lt;Poster&gt;. If we create a flow from the code above, it will be like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2yjSvhXpz8Y9wuqR.png" /></figure><p>But that apparent simplicity hides a serious problem. This compiles and runs. But once you trace the data flow through a full architecture, where the data source feeds a repository that feeds a ViewModel that drives the UI, the problems become clear.</p><h4>The problems with conventional response handling</h4><p>The code above has three major issues that compound as your project grows and the number of API endpoints increases.</p><p><strong>Ambiguous results<br></strong>The data source returns emptyList() for both HTTP errors and network exceptions. Downstream layers (the repository, the ViewModel) receive a List&lt;Poster&gt; with no way to distinguish between three completely different scenarios:</p><ol><li>The request succeeded and the server returned an empty list.</li><li>The request failed with a 401 Unauthorized error.</li><li>The device had no network connectivity.</li></ol><p>All three produce the same result: an empty list. The repository cannot decide whether to show an error message, redirect to a login screen, or display “no data” content. The ViewModel might show an empty state when it should be showing a “please log in” dialog. The response has lost its context, and once that context is gone, no amount of downstream logic can recover it.</p><p>You might try to work around this by returning null for failures instead of emptyList(). But that introduces its own ambiguity: does null mean &quot;error&quot; or &quot;no data&quot;? You end up needing a wrapper type anyway, which leads to the next problem. That&#39;s just adding one more implicit convention on your head.</p><p><strong>Boilerplate error handling<br></strong>Every API call requires its own try-catch block. If you have 20 service methods, you write 20 nearly identical try-catch blocks. Each one catches HttpException, catches Throwable, and returns some fallback value. This repetition creates maintenance overhead and increases the surface area for mistakes, like forgetting to handle a specific exception type in one of the 20 call sites.</p><p>Consider a data source with multiple methods:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03fb64e2e5dea330c984036bec620104/href">https://medium.com/media/03fb64e2e5dea330c984036bec620104/href</a></iframe><p>The pattern is identical every time: try the call, catch HttpException, catch Throwable, return a fallback. The only thing that changes is the fallback value (null, emptyList(), false). This is textbook boilerplate that should not exist in every data source class.</p><p><strong>One dimensional response processing<br></strong>The repository and presentation layers receive only the raw data type (List&lt;Poster&gt;, User?, Boolean). They have no access to HTTP status codes, error bodies, or exception details. If the ViewModel needs to show a specific error message based on the HTTP status code, for example &quot;Your session has expired&quot; for 401 or &quot;Server is undergoing maintenance&quot; for 503, the data source must somehow encode that information into the return type.</p><p>You either propagate exceptions upward (which defeats the purpose of catching them), create custom sealed classes for every API call (which creates even more boilerplate), or lose the information entirely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xNqpgGs9R-suM_r_.png" /></figure><p>What you actually need is a single type that encapsulates the full outcome of an API call, success data, error details, or exception information, and that can flow through every layer without losing any context along the way. That is exactly what Sandwich provides.</p><h4>Hello Sandwich</h4><p><a href="https://github.com/skydoves/sandwich">Sandwich</a> is a Kotlin Multiplatform library that constructs standardized response types for API and I/O calls using sealed types. It provides a lightweight ApiResponse type that models success, error, and exception cases as distinct subtypes, along with a rich set of composable extension functions for handling, transforming, recovering, validating, filtering, and combining responses cleanly across your architecture.</p><p>Sandwich works with <a href="https://github.com/square/retrofit">Retrofit</a>, <a href="https://github.com/ktorio/ktor">Ktor</a>, and <a href="https://github.com/Foso/Ktorfit">Ktorfit</a>. It does not require annotation processing, code generation, or custom Gradle plugins. The integration is a single line of configuration.</p><p><strong>Setup<br></strong>Add the dependency to your module’s build.gradle.kts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ee98a34534ff86261b10ee6e17d074d/href">https://medium.com/media/8ee98a34534ff86261b10ee6e17d074d/href</a></iframe><p>For Retrofit, add the ApiResponseCallAdapterFactory to your Retrofit builder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13d763d91caf9b9e3b3e8d1c783cde7f/href">https://medium.com/media/13d763d91caf9b9e3b3e8d1c783cde7f/href</a></iframe><p>The ApiResponseCallAdapterFactory intercepts every Retrofit call and wraps the result into an ApiResponse. It handles successful responses, HTTP errors, and network exceptions automatically. You do not need to add any try-catch blocks or custom interceptors.</p><p>Then change your service return type to ApiResponse&lt;T&gt;:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0304902a44641ae59d54a0e94bf76292/href">https://medium.com/media/0304902a44641ae59d54a0e94bf76292/href</a></iframe><p>That is the entire setup. Your service method now returns ApiResponse&lt;List&lt;Poster&gt;&gt; instead of List&lt;Poster&gt;. Every possible outcome, success, HTTP error, network exception, is captured in this single return type.</p><p>For Ktor, you can use the apiResponseOf extension function that wraps any Ktor HttpResponse:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce0889c458c93832facd76d42c306c60/href">https://medium.com/media/ce0889c458c93832facd76d42c306c60/href</a></iframe><p>For Ktorfit, add the ApiResponseConverterFactory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aa83ae4efbd2550667dea644bace64f/href">https://medium.com/media/6aa83ae4efbd2550667dea644bace64f/href</a></iframe><p>All three integrations produce the same ApiResponse&lt;T&gt; type, so the rest of your architecture (repository, ViewModel, UI) works identically regardless of which HTTP client you use.</p><h4>ApiResponse</h4><p>ApiResponse is a sealed interface with three subtypes that model every possible outcome of an API call. Understanding the distinction between these three types is fundamental to using Sandwich effectively.</p><p>Basically, ApiResponse consists of the following three subclasses: ApiResponse.Success, ApiResponse.Failure.Error, and ApiResponse.Failure.Exception:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PPNjRyz3fRaQ3FEj.png" /></figure><p><strong>ApiResponse.Success<br></strong>Represents a successful response where the server returned a 2xx status code and the response body was deserialized without errors. This is the happy path. The data property contains the deserialized response body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afd77c7ecb82e77779248ccc7f5e0680/href">https://medium.com/media/afd77c7ecb82e77779248ccc7f5e0680/href</a></iframe><p>For Retrofit integration, ApiResponse.Success also carries the original response metadata, which you can access through platform specific extensions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e927af426564f9d36953d129c69688e1/href">https://medium.com/media/e927af426564f9d36953d129c69688e1/href</a></iframe><p>This is useful when you need to read pagination headers, cache control directives, or rate limit information from a successful response.</p><p><strong>ApiResponse.Failure.Error<br></strong>Represents an HTTP error response, where the server received the request and responded, but with a non 2xx status code. This includes 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error, and every other HTTP error code. The error payload (the response body) is available for parsing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2814da399c8abc3e251aa9b4e054892c/href">https://medium.com/media/2814da399c8abc3e251aa9b4e054892c/href</a></iframe><p>With Retrofit, the payload contains the original okhttp3.Response, so you can read the error body, status code, and headers. With Ktor, the payload contains the HttpResponse. In both cases, the full error context is preserved.</p><p><strong>ApiResponse.Failure.Exception<br></strong>Represents a client side exception that occurred before receiving any HTTP response from the server. This is fundamentally different from Failure.Error. An Error means the network request completed and the server sent back an error response. An Exception means the request never completed at all. Common causes include:</p><ul><li>Network connectivity failures (airplane mode, no Wi-Fi).</li><li>DNS resolution errors (server hostname cannot be resolved).</li><li>Connection timeouts (server did not respond in time).</li><li>SSL/TLS handshake failures (certificate issues).</li><li>JSON parsing errors (response body could not be deserialized).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca9dc60e2d52f0be47ab9cb9ee2a1116/href">https://medium.com/media/ca9dc60e2d52f0be47ab9cb9ee2a1116/href</a></iframe><p>This distinction matters for your UI. When the server returns a 401 Unauthorized (Failure.Error), you might show &quot;Please log in again.&quot; When the device has no network (Failure.Exception), you might show &quot;Check your internet connection.&quot; Without this distinction, you cannot give your users the right guidance.</p><h4>Handling ApiResponse</h4><p>Now that ApiResponse captures every outcome, you need a clean way to handle each case. Sandwich provides chainable extension functions that execute scoped lambdas based on the response type:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8799117c1fe2604e41d16023fe8eea1c/href">https://medium.com/media/8799117c1fe2604e41d16023fe8eea1c/href</a></iframe><p>Each lambda only executes when the response matches its type. The onSuccess block runs only on success, onError only on HTTP errors, and onException only on client side exceptions. The key design here is that each extension returns the original ApiResponse, so all three handlers can be chained in a single expression. Only the matching handler executes; the others are skipped silently.</p><p>Inside each lambda, this is set to the corresponding ApiResponse subtype. Inside onSuccess, you can access data and tag directly. Inside onError, you can access payload and call message(). Inside onException, you can access throwable and message. There is no manual casting required.</p><p>If you do not need to distinguish between error and exception, you can use onFailure to handle both failure types in a single block:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/057fed487997ef913f6279c60c4484e3/href">https://medium.com/media/057fed487997ef913f6279c60c4484e3/href</a></iframe><p>This is convenient when your UI shows the same error state regardless of whether the failure was a server error or a network exception.</p><p>Exhaustive handling with when</p><p>You can also use Kotlin’s when expression for exhaustive matching:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50d6a70ad789f10f7ead7f67931b5149/href">https://medium.com/media/50d6a70ad789f10f7ead7f67931b5149/href</a></iframe><p>Because ApiResponse is a sealed interface, the compiler verifies that all cases are handled. If a new subtype were ever added, every when expression without an else branch would produce a compile time error until updated. This gives you compile time safety that your error handling is complete.</p><h4>Multi layered architecture with ApiResponse</h4><p>With ApiResponse, your entire architecture changes. The data source becomes trivial because it no longer needs try-catch blocks, fallback values, or any error handling at all:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1446897d4e5c1cfbc7118bde26337a3/href">https://medium.com/media/d1446897d4e5c1cfbc7118bde26337a3/href</a></iframe><p>Compare this with the original version that had nested try-catch blocks returning emptyList(). The data source is now a straightforward pass through. All error context is preserved in the ApiResponse.</p><p>The repository can apply business logic while keeping the ApiResponse wrapper intact. For example, it might cache successful results or enrich the response with local data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/271faaa277b7de101ff0bf49a8236082/href">https://medium.com/media/271faaa277b7de101ff0bf49a8236082/href</a></iframe><p>The ViewModel handles each case with full context, making the right UI decision for each scenario:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7933f1ab80b04b8ccee12abcfb2647eb/href">https://medium.com/media/7933f1ab80b04b8ccee12abcfb2647eb/href</a></iframe><p>The response carries its full context through every layer. The ViewModel can distinguish between empty data (a successful response with an empty list), server errors (401, 500, etc.), and network failures (no connectivity, timeout) without the data source losing any information along the way. Each layer adds its own logic without stripping away the information that other layers need.</p><h4>Retrieving data directly</h4><p>Sometimes you do not need the full chained handling and just want to extract the data from a response. Sandwich provides three extraction functions for this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82481ba0b4b9d8499a93837ad07e9ee9/href">https://medium.com/media/82481ba0b4b9d8499a93837ad07e9ee9/href</a></iframe><p>getOrNull() is useful in contexts where you just need the data and can handle null downstream, such as inside a let block or when combining with other nullable operations. getOrElse() is ideal when you have a sensible default value, like an empty list for a collection endpoint.</p><p>getOrThrow() is for cases where you want to propagate the failure as an exception, which can be useful at the boundary between Sandwich code and legacy code that expects exceptions.</p><p>You can also use getOrElse with a lambda for lazy default evaluation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/787c985717178273fbd14f515dfb0cc7/href">https://medium.com/media/787c985717178273fbd14f515dfb0cc7/href</a></iframe><h4>ApiResponse with Coroutines and Flow</h4><p>For reactive architectures that use Kotlin Flow, Sandwich provides suspend extensions that allow you to call suspend functions inside the handler scopes. This is essential because standard onSuccess, onError, and onException accept non suspend lambdas, which means you cannot call database operations, additional network requests, or other suspend functions inside them.</p><p>The suspend variants, suspendOnSuccess, suspendOnError, and suspendOnException, solve this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b52a7ca7f9b844073922544680916578/href">https://medium.com/media/b52a7ca7f9b844073922544680916578/href</a></iframe><p>This pattern is useful because each handler scope is a suspend lambda. You can perform database insertions, additional API calls, file I/O, or any other suspend work directly inside the handler without nesting coroutine builders. The Flow collects the emitted data and propagates it downstream to the UI layer.</p><p>Converting to Flow directly</p><p>If you only need the success data as a Flow and want to handle failures separately, Sandwich provides the toFlow() extension:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3953e27936b370e04f046b88c2e9af39/href">https://medium.com/media/3953e27936b370e04f046b88c2e9af39/href</a></iframe><p>The toFlow() extension creates a Flow that emits the success data. If the response is a failure, the Flow emits nothing (it returns emptyFlow()). This is useful when you handle failures through side effects (logging, showing a toast) and only want the success data to flow into your state.</p><p>You can also transform the data during the conversion. This is a common pattern in repository layers where you want to cache the API response and then return data from the local database:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/082a45b037f3d44a3eae93fd5dc2101b/href">https://medium.com/media/082a45b037f3d44a3eae93fd5dc2101b/href</a></iframe><p>The lambda receives the success data and returns the transformed result. The database operations run inside the Flow’s coroutine context, so everything is suspend safe. With this approach, now you can have a very unified response type across all different multi layers as like the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dGQnAJh0hjgPW88-.png" /></figure><h4>Mapping and transforming responses</h4><p>Real world APIs rarely return data in the exact shape your UI needs. The server might return a UserAuthResponse with tokens and metadata, but your ViewModel only needs a LoginInfo with the user object and token string. Sandwich provides mapping extensions that transform the data inside an ApiResponse without breaking the response chain or losing failure context.</p><p><strong>mapSuccess<br></strong>Transforms the success data from type T to type V. If the response is a failure, mapSuccess passes it through unchanged:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b511e8c5c37fce3ad98bed95c4718810/href">https://medium.com/media/b511e8c5c37fce3ad98bed95c4718810/href</a></iframe><p>This is particularly useful in repository layers where you want to convert API models into domain models. The repository exposes ApiResponse&lt;LoginInfo&gt; to the ViewModel, while the service returns ApiResponse&lt;UserAuthResponse&gt;. The mapping happens in one place, and failure responses pass through untouched.</p><p>Another common use case is extracting a single item from a list response:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/285857299b81a171e717cc0432d19964/href">https://medium.com/media/285857299b81a171e717cc0432d19964/href</a></iframe><p><strong>mapFailure<br></strong>Transforms the failure payload. This is useful when you want to normalize error bodies across different endpoints:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d3aa576a0cca80d261d5003ab02e01f/href">https://medium.com/media/6d3aa576a0cca80d261d5003ab02e01f/href</a></iframe><p><strong>flatMap<br></strong>Transforms an ApiResponse into a completely different ApiResponse. Unlike mapSuccess which only transforms the success data, flatMap gives you access to the entire response and lets you return any ApiResponse type. This is powerful for mapping server error bodies into custom error types:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa512cd95048e14d170b7c0e568ab046/href">https://medium.com/media/fa512cd95048e14d170b7c0e568ab046/href</a></iframe><p>After this flatMap, the response is either the original ApiResponse.Success (untouched) or one of your custom error types (LimitedRequest, WrongArgument). Downstream layers can pattern match on these custom types without parsing error bodies again.</p><h4>Sequential dependent requests</h4><p>Many real world workflows require chaining multiple API calls where each call depends on the result of the previous one. For example: first fetch an authentication token, then use that token to fetch user details, then use the user’s name to query their posters. If any step fails, the entire chain should fail with that step’s error.</p><p>Sandwich provides the then and suspendThen infix functions for this exact pattern:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2044710355424dd395ff1868cc900997/href">https://medium.com/media/2044710355424dd395ff1868cc900997/href</a></iframe><p>If getUserToken fails, getUserDetails and queryPosters are never called. The failure from the first call propagates directly to the final onFailure handler. If getUserToken succeeds but getUserDetails fails, queryPosters is skipped and the error from getUserDetails propagates. This eliminates deeply nested callbacks or chained if checks.</p><p>You can also combine suspendThen with mapSuccess to transform the final result:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e5c1fa5eff7c545cca94ee53ede6596/href">https://medium.com/media/6e5c1fa5eff7c545cca94ee53ede6596/href</a></iframe><h4>Recovery and fallbacks</h4><p>Network requests fail. Servers go down, devices lose connectivity, and APIs return unexpected errors. Sandwich provides recovery extensions that let you define fallback behavior when a request fails, without losing the composability of the response chain.</p><p><strong>recover<br></strong>Returns an ApiResponse.Success with a fallback value if the response is a failure. If the response is already successful, it passes through unchanged:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a4e1153333864b5c1ca787acaa85ca1/href">https://medium.com/media/2a4e1153333864b5c1ca787acaa85ca1/href</a></iframe><p>This is similar to returning emptyList() in a catch block, but with an important difference: the recovery happens after all the response context has been captured. You can chain recover with other extensions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9faacacf1e0e41890ec59a364c4620dd/href">https://medium.com/media/9faacacf1e0e41890ec59a364c4620dd/href</a></iframe><p>Here, the error is logged and reported before the recovery produces a fallback value. The logging and crash reporting still see the original failure. With a try-catch approach, you would need to catch the exception, log it, and then return the fallback, all in the same block.</p><p>For lazy evaluation, use the lambda variant:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ec10d3c667e386f52d7f91d84840051/href">https://medium.com/media/6ec10d3c667e386f52d7f91d84840051/href</a></iframe><p>The lambda is only called when the response is a failure, so the database query does not run on successful requests.</p><p><strong>recoverWith<br></strong>Recovers a failure by executing an alternative operation that itself returns an ApiResponse. This is useful when your fallback is another API call or a database query that might also fail:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d81826f4898d509b45b2236c39c4adbc/href">https://medium.com/media/d81826f4898d509b45b2236c39c4adbc/href</a></iframe><p>If the primary service fails, the backup service is called. If the backup also fails, that failure is the final result. For suspend fallbacks, use suspendRecoverWith:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24cdcce358912aa59aade984e08d74da/href">https://medium.com/media/24cdcce358912aa59aade984e08d74da/href</a></iframe><h4>Validation</h4><p>Sometimes a successful API response contains data that does not meet your application’s requirements. The server returned a 200 OK, but the data itself is invalid, empty, or missing required fields. Sandwich provides validation extensions that convert a success response into a failure when the data does not pass your criteria.</p><p><strong>validate<br></strong>Validates the success data with a predicate. If the predicate returns false, the response is converted to ApiResponse.Failure.Error with your specified error message:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a561dd268642a226e1786f34abe945c5/href">https://medium.com/media/a561dd268642a226e1786f34abe945c5/href</a></iframe><p>Now downstream handlers will see a Failure.Error if the list is empty, even though the HTTP request technically succeeded. This is useful for APIs that return empty arrays instead of proper error codes when something goes wrong on the server side.</p><p><strong>requireNotNull<br></strong>Requires a specific field within the success data to be non null. If the selected value is null, the response is converted to a failure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe6afddaebccde2dcec3e1f69b953d26/href">https://medium.com/media/fe6afddaebccde2dcec3e1f69b953d26/href</a></iframe><p>This transforms the ApiResponse&lt;User&gt; into an ApiResponse&lt;String&gt; (the profile image URL), validating non null in the same step. It combines extraction and validation into a single operation.</p><p>For suspend validation logic (e.g., checking against a database or calling a validation service), use the suspend variants:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ca1a51b8603228b486e9e76b16f31ec/href">https://medium.com/media/0ca1a51b8603228b486e9e76b16f31ec/href</a></iframe><h4>Filtering list responses</h4><p>For API responses that return lists, Sandwich provides filtering extensions that remove items from the success data based on a predicate:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e85790c1cf4b00dd9ff4d4d69c3583c8/href">https://medium.com/media/e85790c1cf4b00dd9ff4d4d69c3583c8/href</a></iframe><p>This returns an ApiResponse&lt;List&lt;Poster&gt;&gt; containing only active posters. On failure responses, the filter has no effect; the failure passes through unchanged.</p><p>The inverse is also available:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2c4fb54e8c229c0b17556b50381ea85/href">https://medium.com/media/b2c4fb54e8c229c0b17556b50381ea85/href</a></iframe><p>These are especially useful when the server does not support filtering queries and you need to filter on the client side. You can chain filters with other extensions for a complete pipeline:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fd1bd78f01ba10d15ac868802c052f7/href">https://medium.com/media/1fd1bd78f01ba10d15ac868802c052f7/href</a></iframe><p>This validates the list is not empty, filters to active items, sorts by creation date, and falls back to an empty list if anything fails. Each step composes cleanly because they all operate on ApiResponse&lt;List&lt;Poster&gt;&gt;.</p><h4>Combining multiple responses</h4><p>Many screens need data from multiple API endpoints. A home screen might need user profile data and a list of recommended posters. A dashboard might need settings, notifications, and activity data. Sandwich provides zip extensions that combine multiple ApiResponse instances into a single response.</p><p><strong>zip<br></strong>Combines two ApiResponse instances. If both are successful, the transform function runs. If either is a failure, the first failure is returned:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e3e52509bf5a24544dfb49c689c2bb0/href">https://medium.com/media/8e3e52509bf5a24544dfb49c689c2bb0/href</a></iframe><p>This is cleaner than nesting two onSuccess handlers or using async/await with manual error checking. If the users call succeeds but the posters call fails, you get the posters failure as the combined result. No partial data, no inconsistent state.</p><p>For a simple pair without transformation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e90181765ec19f6f9e6e1e926d686b7d/href">https://medium.com/media/e90181765ec19f6f9e6e1e926d686b7d/href</a></iframe><h4>Merging paginated responses</h4><p>When you need to fetch multiple pages of the same endpoint and combine the results into a single response, Sandwich provides the merge extension:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc3e9e49a745adc23c0e1d45c9ce984c/href">https://medium.com/media/dc3e9e49a745adc23c0e1d45c9ce984c/href</a></iframe><p>The mergePolicy parameter controls how failures are handled. PREFERRED_FAILURE returns a failure if any page fails. IGNORE_FAILURE collects the successful pages and ignores failures, which is useful when you want partial results.</p><h4>Observing responses with peek</h4><p>Peek extensions let you observe a response for side effects without modifying it. This is the right tool for logging, analytics, caching, and crash reporting, operations that should happen as a side effect of the response but should not change the response itself:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6625175a1bbe6df6eb38fc450ee18cdf/href">https://medium.com/media/6625175a1bbe6df6eb38fc450ee18cdf/href</a></iframe><p>Each peek extension returns the original ApiResponse unchanged. You can chain peek calls before or after any other extension. This is useful for building an observation pipeline that runs independently of your handling logic:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b14ae31169bd25e0f6f071859e3c9a7/href">https://medium.com/media/4b14ae31169bd25e0f6f071859e3c9a7/href</a></iframe><p>There is also a generic peek that runs on any response type:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3adc744e902c44c200bfeadad928d98/href">https://medium.com/media/f3adc744e902c44c200bfeadad928d98/href</a></iframe><p>For suspend side effects (like writing to a cache or database), use the suspend variants: suspendPeekSuccess, suspendPeekError, suspendPeekException, suspendPeekFailure, and suspendPeek.</p><h4>Custom error types</h4><p>Real world APIs return structured error bodies with error codes and messages. You want your Kotlin code to handle these as typed objects, not raw strings or JSON. Sandwich lets you define custom error and exception types by extending ApiResponse.Failure.Error or ApiResponse.Failure.Exception:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eff1ea076d80e663a37c2e43c6b2526f/href">https://medium.com/media/eff1ea076d80e663a37c2e43c6b2526f/href</a></iframe><p>These custom types work with ApiResponse&lt;T&gt; for any T, because Failure.Error and Failure.Exception extend Failure&lt;Nothing&gt;, which is compatible with any generic parameter through Kotlin&#39;s covariance.</p><p>In downstream layers, you can pattern match on your custom types directly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06f6af606289f8761dd4cc2e13829307/href">https://medium.com/media/06f6af606289f8761dd4cc2e13829307/href</a></iframe><h4>Global failure mappers</h4><p>Defining custom error types is useful, but you still need to parse the error body and create the right custom type. Doing this with flatMap on every API call brings back the boilerplate problem. Sandwich solves this with global failure mappers that you register once during application initialization:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9a7077fea91401a8b0647571121915d/href">https://medium.com/media/a9a7077fea91401a8b0647571121915d/href</a></iframe><p>Once registered, this mapper transforms every ApiResponse.Failure across your entire application automatically. Every API call, whether it is posterService.fetchPosterList(), userService.fetchUser(), or authService.login(), goes through the mapper. Your ViewModels and repositories only need to handle the custom types:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c95f7d0630f1ff577b4335c36b364d8/href">https://medium.com/media/4c95f7d0630f1ff577b4335c36b364d8/href</a></iframe><p>For Ktor or Ktorfit where reading the error body requires a suspend function (like HttpResponse.bodyAsText()), use ApiResponseFailureSuspendMapper:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c33ea7ca487b0a6d8555bc6ddf0c54ac/href">https://medium.com/media/c33ea7ca487b0a6d8555bc6ddf0c54ac/href</a></iframe><p>The suspend mapper is properly awaited in suspend contexts, ensuring the mapped response is returned correctly to callers. You can register both synchronous and suspend mappers in the same list, and they will be applied in order.</p><h4>Global operators</h4><p>While failure mappers transform failure responses, global operators observe every response (including successes) for cross cutting concerns. This is the right tool for centralized logging, analytics, authentication token refresh, or showing global error indicators:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd0e103e22e13e6d1599288a77db1cda/href">https://medium.com/media/cd0e103e22e13e6d1599288a77db1cda/href</a></iframe><p>This operator runs on every ApiResponse created through ApiResponse.of or ApiResponse.suspendOf (which includes all Retrofit, Ktor, and Ktorfit responses). The 401 handling in the example above applies globally: any API call that returns a 401 triggers the auth manager, without requiring each call site to check for it.</p><p>For suspend operators, use ApiResponseSuspendOperator which properly awaits in suspend contexts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed57a1ef479a6e8f92a65038733eebec/href">https://medium.com/media/ed57a1ef479a6e8f92a65038733eebec/href</a></iframe><h4>Conclusion</h4><p>Conventional API response handling with try-catch blocks leads to ambiguous results, repetitive boilerplate, and lost context as data flows through layered architectures. Each layer that catches and re-wraps exceptions strips away the information that downstream layers need to make informed UI decisions. A ViewModel that receives emptyList() cannot tell whether the server returned no data, the user&#39;s token expired, or the device lost network connectivity.</p><p><a href="https://github.com/skydoves/sandwich">Sandwich</a> solves this by introducing ApiResponse, a sealed type that captures success data, HTTP error details, and exception information in a single value that flows transparently through every layer. The ApiResponseCallAdapterFactory integrates with Retrofit in one line, the apiResponseOf extension works with Ktor, and the ApiResponseConverterFactory bridges Ktorfit. Beyond basic handling, the full extension API, chained handlers, mapping, sequential composition, recovery, validation, filtering, zipping, merging, peeking, and global interception, composes cleanly to address the real world patterns that every production application encounters.</p><p>If you want to explore Sandwich further, check out the <a href="https://skydoves.github.io/sandwich/">official documentation</a>, the <a href="https://github.com/skydoves/sandwich">GitHub repository</a>, and the real world sample projects like <a href="https://github.com/skydoves/pokedex">Pokedex</a> that demonstrate Sandwich.</p><p>As always, happy coding!</p><p>— Jaewoong</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39ab02ae8c90" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/scalable-api-response-handling-across-multi-layered-architectures-with-sandwich-39ab02ae8c90">Scalable API Response Handling Across Multi-Layered Architectures with Sandwich</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[Announcing Landscapist Core: A New Image Loading Library for Android & Compose Multiplatform]]></title>
            <link>https://proandroiddev.com/announcing-landscapist-core-a-new-image-loading-library-for-android-compose-multiplatform-6a4f408cba00?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a4f408cba00</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sun, 04 Jan 2026 09:21:25 GMT</pubDate>
            <atom:updated>2026-01-16T15:05:58.612Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bSOjB7UDO0iNn79c" /><figcaption>Unsplash@britishlibrary</figcaption></figure><p>Image loading has always been a fundamental challenge in mobile and cross-platform development. While Android developers have relied on battle-tested libraries like Glide, Coil, and Fresco for years, the rise of Kotlin Multiplatform has created a gap: how do you load images consistently across Android, iOS, Desktop, and Wasm without duplicating code or depending on platform-specific solutions? This is precisely the problem <a href="https://skydoves.github.io/landscapist/landscapist/landscapist-core/">Landscapist Core</a> solves.</p><p>In this article, you’ll explore the architecture behind Landscapist Core, a standalone Kotlin Multiplatform image loading engine, and <a href="https://skydoves.github.io/landscapist/landscapist/landscapist-image/">Landscapist Image</a>, its Compose Multiplatform UI companion. You’ll examine the design decisions that make this library exceptionally lightweight, understand how it achieves cross-platform consistency, and learn practical patterns for integrating it into your applications. Whether you’re building a consumer app or a library/SDK that needs to minimize its footprint, understanding Landscapist’s approach offers valuable insights into modern image loading architecture.</p><blockquote>If you want to deeply explore the <em>how</em> and <em>why</em> behind Kotlin, from core language fundamentals and internal mechanisms to API design, check out <a href="https://kotlin.skydoves.me/"><strong><em>Practical Kotlin Deep Dive</em></strong></a>, a new Kotlin book by this author.</blockquote><p><a href="https://kotlin.skydoves.me/">Practical Kotlin Deep Dive | Master Kotlin, Coroutines, Flow &amp; Multiplatform</a></p><h4>The problem with existing solutions</h4><p>Before diving into Landscapist Core, it’s worth understanding why a new image loading library is needed when mature solutions already exist.</p><p>When Compose Multiplatform emerged as a serious cross-platform UI framework, the image loading story remained fragmented. Developers cobbled together solutions: Glide/Coil on Android, platform-specific loaders elsewhere, or custom implementations that duplicated effort. This has been a long-standing item on my TODO list since the initial launch of the <a href="https://github.com/skydoves/landscapist">Landscapist library</a> in 2020. Over time, I found myself looking for:</p><ol><li>A unified solution: consistent APIs and behavior across all Compose Multiplatform targets.</li><li>Just lightweight: I’ve been working on a ton of third-party solutions, such as libraries and SDKs, so I wanted to make everything lightweight and focus only on core capabilities such as network fetching, memory and disk caching, decoding and downsampling, and progressive loading.</li><li>Extremely optimized performance for Jetpack Compose.</li></ol><p>For SDK developers, every kilobyte matters. When you ship a library that includes image loading capabilities, your users inherit your dependencies. At ~312 KB, <a href="https://skydoves.github.io/landscapist/landscapist/landscapist-core/">Landscapist Core</a> is remarkably small compared to Coil3 (~460 KB, +47% larger), Glide (~689 KB, +121% larger), and Fresco (~1 MB, +228% larger). This isn’t accidental; it’s the result of deliberate architectural choices that focus on essential functionality while keeping the design simple.</p><p>Then, is Landscapist the best for every case? No, Coil3 is probably a very safe choice in many cases due to its maturity. Landscapist Core’s main value is:</p><ol><li>Highly optimized for Compose, reducing unnecessary recompositions and improving startup time with Baseline Profiles.</li><li>SDK/library developers who need every KB savings.</li><li>Beyond the core engine, Landscapist offers a rich plugin ecosystem including placeholder animations (shimmer, fade, resonate), image transformations (blur), transition animations (crossfade, circular reveal), palette extraction, and advanced zoomable support with subsampling for high-resolution images.</li><li>Projects already using Landscapist’s plugin ecosystem.</li></ol><p>So let’s explore more about the Landscapist.</p><h4>Landscapist Core: The foundation</h4><p>Landscapist Core is a complete, standalone image loading engine designed for Kotlin Multiplatform from day one. It provides everything needed to fetch, cache, decode, and deliver images, without any UI dependencies.</p><p><strong>Core architecture<br></strong>The architecture follows a pipeline pattern where images flow through distinct stages: from the network or source, through fetching, decoding, transformation, caching, and finally to the result. Each stage is pluggable, allowing customization without modifying core behavior. The design enables several important properties: stages can be skipped when appropriate (cache hits bypass fetching), failures at any stage propagate cleanly, and the entire pipeline is suspendable for efficient coroutine integration.</p><p>On Android, you can create an instance using the builder pattern with a Context:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e3e2adabef82dd4316c80194165f2a4/href">https://medium.com/media/3e3e2adabef82dd4316c80194165f2a4/href</a></iframe><p>This approach automatically configures disk caching in the app’s cache directory and enables Android-specific image sources like Uri, Drawable resources, and content providers.</p><p>Alternatively, you can use the context-free builder and getInstance(), which works across all platforms, including Android:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef3f46d738b84d3dd01446d501717226/href">https://medium.com/media/ef3f46d738b84d3dd01446d501717226/href</a></iframe><p><strong>Loading images with Flow<br></strong>Image loading is inherently asynchronous, and Landscapist embraces Kotlin’s Flow for delivering results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cef3fad183ce09a5541caf2a24c157cd/href">https://medium.com/media/cef3fad183ce09a5541caf2a24c157cd/href</a></iframe><p>The Flow-based API provides several advantages over callback-based alternatives. State changes are delivered sequentially and can be collected multiple times. The loading state is explicit rather than implicit. Cancellation happens automatically when the collecting coroutine is cancelled.</p><p><strong>Memory and disk caching strategy<br></strong>Caching is where image loaders spend most of their complexity budget, and Landscapist’s approach balances simplicity with effectiveness.</p><p><strong>Two-tier cache architecture<br></strong>The caching strategy uses two tiers: a fast in-memory LRU cache and a persistent disk cache.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4c56713ec71642458d142c9b6e7f36a/href">https://medium.com/media/a4c56713ec71642458d142c9b6e7f36a/href</a></iframe><p>The memory cache uses Least Recently Used eviction, automatically removing the oldest entries when the cache exceeds its size limit. The weakReferencesEnabled option is particularly clever: when entries are evicted from the LRU cache, they&#39;re kept as weak references. If the bitmap hasn&#39;t been garbage collected when re-requested, it&#39;s promoted back to the LRU cache without any I/O.</p><p>Different images have different caching requirements. A user’s profile picture should be cached aggressively. A one-time verification image might skip caching entirely. Landscapist provides granular control through cache policies:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6df039bb513e2e76ba7748b35f8fb3de/href">https://medium.com/media/6df039bb513e2e76ba7748b35f8fb3de/href</a></iframe><p><strong>Automatic downsampling<br></strong>Large images are a common source of OutOfMemoryErrors. Landscapist automatically downsamples images based on the target size specified in the request:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff43bd8051eafc55b54e83ed65d9134e/href">https://medium.com/media/ff43bd8051eafc55b54e83ed65d9134e/href</a></iframe><p>The decoder uses the target dimensions to calculate an appropriate sample size, loading a ~400x400 bitmap instead of the full 4000x4000 image. This single optimization often makes the difference between a smooth scrolling list and an app that crashes under memory pressure.</p><h4>Landscapist Image: Compose Multiplatform integration</h4><p>While Landscapist Core handles the image loading pipeline, Landscapist Image provides the Compose Multiplatform UI integration. It’s built on top of the core module and provides seamless integration with Compose’s composition and layout systems.</p><p><strong>Basic usage<br></strong>The simplest usage requires just an image model and a size:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c6f78d973c9edcadf5d0424a26775c7/href">https://medium.com/media/2c6f78d973c9edcadf5d0424a26775c7/href</a></iframe><p>Behind this simple API, several things happen automatically: the size constraints from the modifier are measured during composition, the appropriate cache is checked, the image is fetched if needed, decoded at the target resolution, and rendered.</p><p><strong>Loading state composables<br></strong>Real applications need to handle loading and error states gracefully. Landscapist Image provides composable slots for each state:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cd87f9046cb96b145643f6a43cc6d2c/href">https://medium.com/media/8cd87f9046cb96b145643f6a43cc6d2c/href</a></iframe><p>The composable slots receive relevant state information. The success slot provides both the LandscapistImageState.Success with metadata (data source, original dimensions) and a Painter ready for rendering. The failure slot provides the LandscapistImageState.Failure with the exception that caused the failure.</p><p><strong>State change callbacks<br></strong>For analytics, logging, or coordinating UI state, you can observe state changes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b729c5ea63d452d2831ddbf04d57ff4a/href">https://medium.com/media/b729c5ea63d452d2831ddbf04d57ff4a/href</a></iframe><p><strong>The plugin ecosystem<br></strong>One of Landscapist’s most graceful features is its plugin architecture. Plugins are modular, composable components that extend functionality without modifying core behavior.</p><p>Plugins are added through the component parameter using a DSL:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fbc27c1d95d05ef09324e8d6e618d20/href">https://medium.com/media/0fbc27c1d95d05ef09324e8d6e618d20/href</a></iframe><p>The + operator adds plugins to the component. Plugins are applied in order, allowing you to layer effects. The rememberImageComponent ensures the component configuration survives recomposition.</p><p>The ecosystem includes several production-ready plugins.</p><ul><li><a href="https://skydoves.github.io/landscapist/placeholder/">ShimmerPlugin</a> displays an animated shimmer effect during loading, providing visual feedback that content is loading with customizable colors, duration, and animation parameters.</li><li><a href="https://skydoves.github.io/landscapist/animation/">CrossfadePlugin</a> smoothly crossfades between placeholder and loaded image, essential for polished user experience.</li><li><a href="https://skydoves.github.io/landscapist/animation/#circular-reveal-animation">CircularRevealPlugin</a> reveals the image with an expanding circular animation from the center.</li><li><a href="https://skydoves.github.io/landscapist/transformation/">BlurTransformationPlugin</a> applies a blur effect to loaded images.</li><li><a href="https://skydoves.github.io/landscapist/palette/">PalettePlugin</a> extracts dominant colors from the loaded image, useful for creating dynamic UI that responds to image content.</li><li><a href="https://skydoves.github.io/landscapist/zoomable/">ZoomablePlugin</a> enables pinch-to-zoom and pan gestures on images, and you can apply sub-sampling for Kotlin Multiplatform.</li></ul><p>Plugins can be combined to create sophisticated loading experiences:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f2e750e7344076f54f9f65e512dac96/href">https://medium.com/media/9f2e750e7344076f54f9f65e512dac96/href</a></iframe><p>You can even create your own plugin with the <a href="https://skydoves.github.io/landscapist/image-component-and-plugin/">ImageComponent and ImagePlugin</a>, and everything makes it more flexible for your Jetpack Compose project.</p><h4>Performance characteristics</h4><p>The landscapist’s performance wasn’t an afterthought; it was designed from the beginning with specific performance targets.</p><p>Performance testing against established libraries shows competitive results. LandscapistImage achieves an average load time of 1,245ms with 4,520KB memory usage, while GlideImage takes 1,312ms (+5%) with 5,124KB (+13%), CoilImage takes 1,389ms (+12%) with 4,876KB (+8%), and FrescoImage takes 1,467ms (+18%) with 5,342KB (+18%). These numbers come from standardized benchmark conditions: loading the same set of images from network on identical hardware. Real-world performance varies based on network conditions, cache state, and image characteristics.</p><p>The test methodology; the performance numbers averaged across 5 rounds of instrumented tests on Android 16 emulator. Each test loads a fresh 200KB JPEG from network (GitHub CDN, no cache) at 300dp size. All caches cleared between runs. Measurements from setContent to fully decoded bitmap. You can see <a href="https://github.com/skydoves/landscapist/blob/697ad3f64ab6aa8ec068ce13c82912f579f9454d/app/src/androidTest/kotlin/com/github/skydoves/landscapistdemo/ComprehensivePerformanceTest.kt#L49">ComprehensivePerformanceTest.kt</a> for full implementation.</p><p>Landscapist’s composable functions are designed to be Restartable and Skippable according to Compose compiler metrics. Being Restartable means the function can be re-entered at the point of a state change without re-executing the entire function body. Being Skippable means if inputs haven&#39;t changed, the function can be skipped entirely during recomposition. These properties significantly reduce recomposition overhead in lists and complex UIs where images are common.</p><p>The library also includes Baseline Profiles that pre-compile critical code paths during app installation. This reduces cold-start latency and improves overall responsiveness, particularly noticeable on lower-end devices.</p><h4>Cross-platform considerations</h4><p>Writing truly cross-platform code requires understanding where platforms differ and designing abstractions that hide those differences.</p><p>Landscapist uses Kotlin’s expect/actual mechanism to provide platform-specific implementations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/003798b993048edada88bb0ce9f4bf63/href">https://medium.com/media/003798b993048edada88bb0ce9f4bf63/href</a></iframe><p>The common code works with the abstraction; platforms provide concrete implementations.</p><p>Different platforms support different image sources. Android supports network URLs, Content URIs, file paths, Drawable resources, Bitmaps, and byte arrays. iOS and Desktop support network URLs and file paths. Web supports network URLs only. The ImageRequest.builder().model() accepts Any?, and the platform-specific fetcher resolves the appropriate loading strategy.</p><p>Ktor provides the cross-platform HTTP client, with automatic engine selection per platform: OkHttp on Android, Darwin on iOS/macOS, CIO on Desktop, and JS on Web. Ktor engines are bundled automatically based on your target platforms, so you don’t need to add Ktor dependencies manually.</p><h4>Migration from existing Landscapist libraries</h4><p>Migrating to Landscapist Core from existing Landscapist libraries is designed to be straightforward. If you’re already using Landscapist’s other components (GlideImage, CoilImage, FrescoImage), migration is a near drop-in replacement:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/159ffaf3be17638fb8c39e170574ee08/href">https://medium.com/media/159ffaf3be17638fb8c39e170574ee08/href</a></iframe><p>The API is intentionally similar. The same plugins work with both. The primary difference is that LandscapistImage uses the standalone core engine instead of delegating to Glide, Coil, or Fresco.</p><p>The concepts from other Compose image loading solutions also map reasonably well:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2f3146d3d041241ec67c8c17a3f5f0e/href">https://medium.com/media/a2f3146d3d041241ec67c8c17a3f5f0e/href</a></iframe><h4>When to choose Landscapist</h4><p>Landscapist Core and Landscapist Image are particularly good for specific scenarios. If you’re building an SDK that needs image loading capabilities, Landscapist’s minimal footprint is compelling. At ~312 KB, it adds minimal weight to your users’ APKs. Compare this to bundling Glide (~689 KB) or Fresco (~1 MB), and the difference compounds across your SDK’s install base.</p><p>For Compose Multiplatform applications targeting Android, iOS, Desktop, or Wasm, Landscapist provides a unified solution. Write your image loading code once in common source sets, and it works identically across all platforms. If you’re starting a new project and don’t need library-specific features (Glide’s resource management, Coil’s extension ecosystem, Fresco’s streaming architecture), Landscapist offers a simpler mental model with fewer concepts to learn.</p><p>Landscapist may not be the best choice if you need Glide’s extensive transformation library or resource lifecycle integration, you’re heavily invested in Coil’s interceptor and extension ecosystem, you require Fresco’s progressive streaming for very large images, or your project is Android-only and you need proven library-specific optimizations. So, it very depends on your choice, even though we can’t say ‘A’ is the best in every single case.</p><h4>Conclusion</h4><p>Landscapist Core represents a thoughtful approach to the image loading problem in the Kotlin Multiplatform era. By starting fresh rather than wrapping existing libraries, it achieves a remarkably small footprint (~312 KB) while providing production-ready functionality across Android, iOS, Desktop, and Wasm.</p><p>The architecture separates concerns cleanly: Landscapist Core handles the image loading pipeline without UI dependencies, while Landscapist Image provides Compose Multiplatform integration with a graceful plugin ecosystem. This separation enables use cases from headless image pre-loading to sophisticated UI with shimmer effects, crossfades, and color extraction.</p><p>Performance is competitive with established solutions, composable functions are optimized for Compose’s recomposition system, and Baseline Profiles ensure smooth cold-start behavior. For SDK developers, the minimal footprint means you can add image loading capabilities without significantly impacting your users’ app sizes.</p><p>Whether you’re building a Compose Multiplatform application, developing an SDK that needs to stay lean, or simply want a unified image loading solution across platforms, Landscapist provides a solid foundation. The library continues to evolve with the Kotlin Multiplatform ecosystem, and its architecture positions it well for future platform expansions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a4f408cba00" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/announcing-landscapist-core-a-new-image-loading-library-for-android-compose-multiplatform-6a4f408cba00">Announcing Landscapist Core: A New Image Loading Library for Android &amp; Compose Multiplatform</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[Inside Jetpack ViewModel: Internal Mechanisms and Multiplatform Design]]></title>
            <link>https://proandroiddev.com/inside-jetpack-viewmodel-internal-mechanisms-and-multiplatform-design-2625671eaef8?source=rss-9bb203a4ab2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2625671eaef8</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Jaewoong Eum]]></dc:creator>
            <pubDate>Sun, 07 Dec 2025 02:29:08 GMT</pubDate>
            <atom:updated>2025-12-07T18:14:16.915Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tOtkLxn9LUT6ZAsI" /><figcaption>Unsplash@davidvig</figcaption></figure><p>Jetpack’s ViewModel has become an essential component of modern Android development, providing a lifecycle-aware container for UI-related data that survives configuration changes. While the API appears simple on the surface, the internal machinery reveals design decisions around lifecycle management, multiplatform abstraction, resource cleanup, and thread-safe caching. Understanding how ViewModel works under the hood helps you make better architectural decisions and avoid subtle bugs.</p><p>In this article, you’ll dive deep into how Jetpack ViewModel works internally, exploring how the ViewModelStore retains instances across configuration changes, how ViewModelProvider orchestrates creation and caching, how the factory pattern enables flexible instantiation, how CreationExtras enables stateless factories, how resource cleanup is managed through the Closeable pattern, and how viewModelScope integrates coroutines with the ViewModel lifecycle.</p><h3>The fundamental problem: Surviving configuration changes</h3><p>Configuration changes present a fundamental challenge for Android development. When a user rotates their device, changes language settings, or triggers any configuration change, the system destroys and recreates the Activity. Any data stored in the Activity is lost:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82ee86f042e31a1ede3f551f919b4429/href">https://medium.com/media/82ee86f042e31a1ede3f551f919b4429/href</a></iframe><p>The naive approach is to use onSaveInstanceState():</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74f2c1da669e831b1488b3f297d55997/href">https://medium.com/media/74f2c1da669e831b1488b3f297d55997/href</a></iframe><p>This works for small, serializable data. But what about large datasets, network connections, or objects that can’t be serialized? What about ongoing operations like network requests? The Bundle approach fails for these cases, both because of size limitations and because serialization/deserialization is expensive.</p><p>ViewModel solves this by providing a lifecycle-aware container that survives configuration changes through a retained object pattern, not serialization.</p><h3>The ViewModelStore: The retention mechanism</h3><p>At the heart of ViewModel’s configuration-change survival is ViewModelStore, a simple key-value store that holds ViewModel instances:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6c995fb5056a076d1b9ad7470e65e26/href">https://medium.com/media/e6c995fb5056a076d1b9ad7470e65e26/href</a></iframe><p>The implementation is remarkably straightforward, just a MutableMap&lt;String, ViewModel&gt;. The magic isn&#39;t in the store itself, it&#39;s in how the store is retained.</p><h4>Key replacement behavior</h4><p>Notice the put method&#39;s behavior:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6207ddcc16eaf1762f42a9f4b384c9ee/href">https://medium.com/media/6207ddcc16eaf1762f42a9f4b384c9ee/href</a></iframe><p>If a ViewModel already exists with the same key, the old ViewModel is immediately cleared. This ensures proper cleanup when a ViewModel is replaced. You might wonder when this happens, it occurs when you request a ViewModel with the same key but a different type:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f817d300df90e4392fe8dbe22678616a/href">https://medium.com/media/f817d300df90e4392fe8dbe22678616a/href</a></iframe><p>This behavior is validated in the test suite:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c131b2c14097d78cd76d1998bad59231/href">https://medium.com/media/c131b2c14097d78cd76d1998bad59231/href</a></iframe><h4>The ViewModelStoreOwner contract</h4><p>The ViewModelStoreOwner interface defines who owns the store:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd30f972a8446cf261947aa1d777cc4/href">https://medium.com/media/7fd30f972a8446cf261947aa1d777cc4/href</a></iframe><p>This simple interface is implemented by ComponentActivity, Fragment, and NavBackStackEntry. The owner&#39;s responsibility is twofold:</p><ol><li><strong>Retain the store across configuration changes</strong>: The store must survive Activity recreation.</li><li><strong>Clear the store when truly finished</strong>: When the owner is destroyed without recreation, call ViewModelStore.clear() .</li></ol><p>For Activities, this is typically implemented using NonConfigurationInstances, a special mechanism that allows objects to survive configuration changes. The Activity framework retains these objects during onRetainNonConfigurationInstance() and restores them in getLastNonConfigurationInstance().</p><h4>Why a simple map works</h4><p>You might expect a sophisticated caching mechanism, but a simple MutableMap is sufficient because:</p><ol><li><strong>Bounded size</strong>: The number of ViewModels per screen is small (typically 1–5).</li><li><strong>String keys</strong>: Keys are generated from class names, making lookup O(1) with good hash distribution.</li><li><strong>No eviction needed</strong>: ViewModels are cleared only when explicitly requested or when the owner is destroyed.</li><li><strong>Thread safety</strong>: Access is synchronized at the ViewModelProvider level.</li></ol><h3>ViewModelProvider: The orchestration layer</h3><p>ViewModelProvider is the primary API for obtaining ViewModel instances. It orchestrates the interaction between the store, factory, and creation extras:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79f410f5866a2cdac8f1c5650454a4ee/href">https://medium.com/media/79f410f5866a2cdac8f1c5650454a4ee/href</a></iframe><h4>The multiplatform abstraction</h4><p>Notice the ViewModelProviderImpl delegation. The ViewModel library is a Kotlin Multiplatform library, supporting JVM, Android, iOS, and other platforms. Kotlin Multiplatform doesn&#39;t yet support expect classes with default implementations, so the common logic is extracted to internal implementation classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08e0d69034ef6904dca3690df3e704a3/href">https://medium.com/media/08e0d69034ef6904dca3690df3e704a3/href</a></iframe><h4>The get-or-create pattern</h4><p>The getViewModel method implements a classic get-or-create pattern:</p><ol><li><strong>Generate key</strong>: Default key is based on the class’s canonical name.</li><li><strong>Check cache</strong>: Look up existing ViewModel by key.</li><li><strong>Type check</strong>: Verify the cached instance is the correct type.</li><li><strong>Return cached</strong>: If valid, return the cached instance.</li><li><strong>Create new</strong>: If not found or wrong type, create via factory.</li><li><strong>Store</strong>: Put the new instance in the store.</li></ol><h4>Thread safety with synchronized access</h4><p>The synchronized(lock) block ensures thread-safe access. While ViewModel access is typically from the main thread (as indicated by @MainThread), the synchronization protects against edge cases where background threads might access ViewModels, particularly in testing scenarios or when using viewModelScope.</p><h4>The OnRequeryFactory callback</h4><p>The OnRequeryFactory is a special mechanism for factories that need to perform actions when a cached ViewModel is retrieved:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de2124530683725c005635a4efc7be6f/href">https://medium.com/media/de2124530683725c005635a4efc7be6f/href</a></iframe><p>This is used internally by SavedStateHandle to reconnect the ViewModel with the current SavedStateRegistry after configuration changes. When a ViewModel is retrieved from cache, the factory’s onRequery method is called, allowing it to update references that might have changed.</p><h4>Key generation from class names</h4><p>The default key generation prevents accidental conflicts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50db2597d86ba17eb8f07fdbca182526/href">https://medium.com/media/50db2597d86ba17eb8f07fdbca182526/href</a></iframe><p>The prefix &quot;androidx.lifecycle.ViewModelProvider.DefaultKey:&quot; ensures keys don&#39;t collide with custom keys users might provide. The canonical name requirement also explains why local and anonymous classes can&#39;t be ViewModels, they don&#39;t have canonical names:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0987cd1b8e4c19b4ba28909be8c34a4a/href">https://medium.com/media/0987cd1b8e4c19b4ba28909be8c34a4a/href</a></iframe><h3>The Factory pattern: Flexible instantiation</h3><p>ViewModelProvider.Factory is the mechanism for creating ViewModel instances:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c235f655f05af3043c6d3bc8f3d287be/href">https://medium.com/media/c235f655f05af3043c6d3bc8f3d287be/href</a></iframe><h4>The method overload chain</h4><p>The factory interface has three create method variants, forming a chain:</p><ol><li>create(KClass&lt;T&gt;, CreationExtras): The Kotlin-first API, delegates to Java variant</li><li>create(Class&lt;T&gt;, CreationExtras): The primary implementation point, defaults to no-extras variant</li><li>create(Class&lt;T&gt;): Legacy API, throws by default</li></ol><p>This chain allows backwards compatibility while encouraging the modern CreationExtras-based approach.</p><h4>NewInstanceFactory: Reflection-based creation</h4><p>The simplest factory uses reflection to create ViewModels with no-arg constructors:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec403342d12bc579393dfbfd6ca576e6/href">https://medium.com/media/ec403342d12bc579393dfbfd6ca576e6/href</a></iframe><p>The JVM implementation uses reflection with careful error handling:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3b4c7c9a1be73760d1298310cfa0eec/href">https://medium.com/media/c3b4c7c9a1be73760d1298310cfa0eec/href</a></iframe><p>The public modifier check is important for test consistency. In instrumentation tests, R8 may strip access modifiers, making private constructors accessible. JVM tests enforce access restrictions strictly. This explicit check ensures consistent behavior across test environments.</p><h4>AndroidViewModelFactory: Application-aware creation</h4><p>AndroidViewModelFactory extends NewInstanceFactory to support AndroidViewModel, which requires an Application parameter. This factory maintains backwards compatibility while embracing the modern CreationExtras approach:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df651a2275cbe80aeccbb5d2b15c0296/href">https://medium.com/media/df651a2275cbe80aeccbb5d2b15c0296/href</a></iframe><p>The factory implements a cascading resolution strategy: first checking if an Application was passed to the constructor (legacy approach), then looking in CreationExtras via APPLICATION_KEY (modern stateless approach), and finally falling back to NewInstanceFactory for regular ViewModels or throwing if an AndroidViewModel has no Application available.</p><p>The unused: Int parameter in the private constructor is a clever trick to differentiate between overloaded constructors, since the compiler couldn&#39;t otherwise distinguish constructor() from constructor(application: Application?) when called with null.</p><p>The instantiation uses reflection (modelClass.getConstructor(Application::class.java).newInstance(app)), which means your AndroidViewModel subclass must have a constructor accepting exactly one Application parameter. For additional dependencies, you&#39;ll need a custom factory or dependency injection frameworks like Hilt.</p><h4>InitializerViewModelFactory: Lambda-based creation</h4><p>For ViewModels with custom dependencies, InitializerViewModelFactory provides a DSL-based approach that reduces boilerplate:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/168c204a9959c66fcdc0824c015c2a54/href">https://medium.com/media/168c204a9959c66fcdc0824c015c2a54/href</a></iframe><p>The DSL is powered by a builder class that collects initializer lambdas, where each initializer pairs a KClass with its creation lambda:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6fd082307605ca03931a90f37db3e44/href">https://medium.com/media/c6fd082307605ca03931a90f37db3e44/href</a></iframe><p>The @ViewModelFactoryDsl annotation is a DSL marker that prevents nested builder scopes from accidentally accessing outer scope methods. The initializer lambda receives CreationExtras as its receiver, allowing direct access to extras via get().</p><p>At creation time, the factory performs a linear search through initializers to find a matching class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de330b588808e24d0c25dc25ba5e7695/href">https://medium.com/media/de330b588808e24d0c25dc25ba5e7695/href</a></iframe><p>The linear search is acceptable because the number of ViewModels per factory is typically small (1–5) and ViewModel creation happens infrequently (once per lifecycle).</p><h3>CreationExtras: Stateless factory configuration</h3><p>CreationExtras is a type-safe, key-value container for passing configuration to factories without making them stateful. Instead of factories holding dependencies via constructor injection, dependencies are passed at creation time:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5df053baad73ec1103959e10ce09fc28/href">https://medium.com/media/5df053baad73ec1103959e10ce09fc28/href</a></iframe><h4>Type-safe keys</h4><p>Each key is parameterized by the value type it’s associated with, providing compile-time type safety. When you retrieve a value with extras[APPLICATION_KEY], the return type is automatically Application?:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/862665a42702064138d98ba36becac87/href">https://medium.com/media/862665a42702064138d98ba36becac87/href</a></iframe><p>The key creation uses an inline function that creates a new anonymous object implementing the Key interface. Since each key is a unique object instance, keys are compared by identity (===), ensuring no accidental collisions even if two keys have the same type parameter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c55f7cac53f964ee942592931f552675/href">https://medium.com/media/c55f7cac53f964ee942592931f552675/href</a></iframe><h4>MutableCreationExtras for modification</h4><p>The base CreationExtras class is read-only, while MutableCreationExtras allows adding entries. This separation follows Kotlin&#39;s collection design philosophy (like List vs MutableList), preventing factories from accidentally modifying shared extras:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10146fa04031a5ae64f7a2c196d41b60/href">https://medium.com/media/10146fa04031a5ae64f7a2c196d41b60/href</a></iframe><h4>Integration with ViewModelProvider</h4><p>The ViewModelProvider automatically adds the ViewModel’s key to extras before calling the factory, which is essential for features like SavedStateHandle that need the key to scope persistence correctly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35b18371b9b8f3095dfeb9772f172386/href">https://medium.com/media/35b18371b9b8f3095dfeb9772f172386/href</a></iframe><h4>HasDefaultViewModelProviderFactory</h4><p>ViewModelStoreOwner implementations can provide default factory and extras through the HasDefaultViewModelProviderFactory interface. ComponentActivity and Fragment both implement this, providing factories that support SavedStateHandle with APPLICATION_KEY pre-populated:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dd9c5d02884bc5dea32e591dccd481a/href">https://medium.com/media/7dd9c5d02884bc5dea32e591dccd481a/href</a></iframe><p>ComponentActivity and Fragment both implement this interface, providing factories that support SavedStateHandle and proper CreationExtras with APPLICATION_KEY pre-populated.</p><p>When creating a ViewModelProvider from a ViewModelStoreOwner, these defaults are automatically used:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d97ec6e0a2765bd2b08fb9513b879b3f/href">https://medium.com/media/d97ec6e0a2765bd2b08fb9513b879b3f/href</a></iframe><p>This pattern enables progressive enhancement: simple ViewModels work with default factories, while complex ViewModels can receive rich configuration through extras without changing how you obtain the ViewModelProvider.</p><h3>The ViewModel class: Resource management</h3><p>The ViewModel class manages resource lifecycle through the AutoCloseable pattern. The expect keyword indicates this is a Kotlin Multiplatform declaration, where each platform provides its own actual implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b01863f3ed28de153b981979cc7f0d2/href">https://medium.com/media/1b01863f3ed28de153b981979cc7f0d2/href</a></iframe><h4>The ViewModelImpl internal implementation</h4><p>The actual implementation is delegated to ViewModelImpl, following the multiplatform pattern where common logic is extracted to internal classes. The @Volatile annotation on isCleared ensures visibility across threads, which is crucial for the post-clear protection mechanism:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0190ab9a470d27d75e92306b6118962/href">https://medium.com/media/d0190ab9a470d27d75e92306b6118962/href</a></iframe><h4>Two-tier closeable storage</h4><p>The implementation maintains two collections: keyToCloseables for resources that need retrieval after registration (like viewModelScope), and closeables for fire-and-forget cleanup. Using a Set for anonymous closeables prevents duplicate registration from causing double-closing.</p><h4>The clearing sequence</h4><p>When a ViewModel is cleared, resources are cleaned up in a specific order. The isCleared = true flag is set before the synchronized block to prevent concurrent addCloseable calls from adding resources that would be missed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc7daf8f1ff4f97eb592f2e40772748f/href">https://medium.com/media/bc7daf8f1ff4f97eb592f2e40772748f/href</a></iframe><p>The anonymous closeables set is cleared, but keyToCloseables is intentionally kept. This prevents accidental recreation of resources like viewModelScope if code accesses it after clearing.</p><h4>Post-clear protection</h4><p>Adding closeables after clearing immediately closes them, preventing resource leaks in edge cases where coroutines are still running when the ViewModel is cleared:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01022a8fa7b3e4eae44e28251177619f/href">https://medium.com/media/01022a8fa7b3e4eae44e28251177619f/href</a></iframe><p>Also, notice that when adding a keyed closeable, any existing closeable with the same key is automatically closed, enabling replacement patterns.</p><h4>Nullable impl for mocking</h4><p>The JVM implementation has a nullable impl to support mocking frameworks. When you mock a ViewModel, the mock doesn&#39;t call the real constructor, so impl is never initialized. Without the nullable type and safe call (impl?.clear()), tests would crash with NullPointerException:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9d04e01acfd73cec6517de20c29b560/href">https://medium.com/media/c9d04e01acfd73cec6517de20c29b560/href</a></iframe><h3>viewModelScope: Coroutine integration</h3><p>The viewModelScope extension property provides a lifecycle-aware CoroutineScope that&#39;s automatically cancelled when the ViewModel is cleared:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5efc75b2fe08d72f02093a0cc808a77f/href">https://medium.com/media/5efc75b2fe08d72f02093a0cc808a77f/href</a></iframe><h4>Lazy creation with keyed storage</h4><p>The scope is created lazily on first access and stored using the keyed closeable mechanism. The key is intentionally verbose to avoid collisions with user-defined keys:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5455e8813b46732dd4d88824f8271f5d/href">https://medium.com/media/5455e8813b46732dd4d88824f8271f5d/href</a></iframe><h4>CloseableCoroutineScope</h4><p>The bridge between coroutines and the closeable system is CloseableCoroutineScope, which implements both CoroutineScope and AutoCloseable. When close() is called during ViewModel clearing, all running coroutines are cancelled:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fbc5f87aedc19eec178e68aa3b71918/href">https://medium.com/media/5fbc5f87aedc19eec178e68aa3b71918/href</a></iframe><h4>Platform-aware dispatcher selection</h4><p>As a Kotlin Multiplatform library, ViewModel works on platforms without a main thread concept by falling back to EmptyCoroutineContext. Notice the use of Dispatchers.Main.immediate rather than Dispatchers.Main, which avoids unnecessary redispatching when already on the main thread:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2fd70a06c0bc02430c1234163c90314/href">https://medium.com/media/f2fd70a06c0bc02430c1234163c90314/href</a></iframe><h4>SupervisorJob for independent child failure</h4><p>The scope uses SupervisorJob() which allows child coroutines to fail independently. With a regular Job, if one child fails it cancels all siblings. This design matches UI application expectations where a failing network request shouldn&#39;t cancel an ongoing database operation.</p><h3>ViewModelLazy: Kotlin property delegation</h3><p>The viewModels() delegate uses ViewModelLazy:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80c1be6f1013f23f12d5e2cdbdf7408f/href">https://medium.com/media/80c1be6f1013f23f12d5e2cdbdf7408f/href</a></iframe><h4>Double-caching architecture</h4><p>The lazy delegate caches the ViewModel reference locally after first access. This is a double-caching pattern:</p><ol><li><strong>ViewModelStore cache</strong>: The canonical cache that survives configuration changes.</li><li><strong>ViewModelLazy cache</strong>: A local cache to avoid repeated ViewModelProvider creation.</li></ol><p>The local cache is an optimization, creating a ViewModelProvider and looking up the ViewModel is cheap, but caching avoids even that minimal overhead on subsequent accesses.</p><h4>Lambda producers for deferred access</h4><p>All three producers (store, factory, extras) are lambdas, allowing deferred evaluation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5b2b566659980516844a55a1e642ac4/href">https://medium.com/media/a5b2b566659980516844a55a1e642ac4/href</a></iframe><p>This is particularly important for fragments where the Activity might not be available during property initialization.</p><h3>Android-specific: AGP desugaring compatibility</h3><p>Android has a special compatibility layer for handling AGP (Android Gradle Plugin) desugaring issues that arise when mixing libraries compiled against different ViewModel versions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a7aa0d9313e01d13e53e9d91087735/href">https://medium.com/media/c0a7aa0d9313e01d13e53e9d91087735/href</a></iframe><p>This cascade of try-catch blocks handles cases where factories compiled with older ViewModel versions lack newer create method variants. The AbstractMethodError occurs when the runtime calls a method that doesn&#39;t exist in the compiled bytecode, typically when an old factory only has create(Class&lt;T&gt;) but the runtime expects create(Class&lt;T&gt;, CreationExtras). The defensive cascade gracefully degrades through method variants, ensuring ViewModel creation works regardless of library version mismatches.</p><h3>Performance characteristics and design trade-offs</h3><p>The ViewModel system makes several deliberate design trade-offs that balance correctness, flexibility, and performance.</p><h4>Synchronization overhead</h4><p>Both ViewModelProviderImpl and ViewModelImpl use synchronized blocks for thread-safe access:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/432369ffdafc3efc4e0f52929d1509fa/href">https://medium.com/media/432369ffdafc3efc4e0f52929d1509fa/href</a></iframe><p>This adds minimal overhead since ViewModel access typically happens on the main thread, the critical sections are short (simple map operations), and lock contention is rare. The design prioritizes correctness over micro-optimization, since a rare race condition would be far more costly than the imperceptible synchronization overhead.</p><h4>Reflection cost</h4><p>NewInstanceFactory uses Java reflection to dynamically instantiate ViewModel classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27566d49ee5321740810f78592560231/href">https://medium.com/media/27566d49ee5321740810f78592560231/href</a></iframe><p>Reflection is slower than direct constructor calls due to runtime type checking and dynamic method resolution. However, this cost is negligible because ViewModels are created infrequently (once per lifecycle), and the flexibility of instantiating any ViewModel subclass without compile-time knowledge far outweighs the minor overhead.</p><h4>Map-based storage</h4><p>Using MutableMap for ViewModelStore provides O(1) lookup but O(n) clear since each ViewModel must be individually cleared:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/223b9f137e3639012882d5cac4e6c42a/href">https://medium.com/media/223b9f137e3639012882d5cac4e6c42a/href</a></iframe><p>Since ViewModelStores typically hold only 1–5 ViewModels, the linear-time clear has no practical impact. The simplicity of using a standard HashMap makes the code easier to understand and maintain, providing more value than theoretical optimizations for this bounded use case.</p><h4>Nullable impl for mockability</h4><p>The nullable impl in JVM ViewModel adds a null check on every operation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92742db12f3f026c9109adc8d4c1a928/href">https://medium.com/media/92742db12f3f026c9109adc8d4c1a928/href</a></iframe><p>This microscopic overhead enables proper mocking behavior. When mocking frameworks create ViewModel mocks, they bypass the real constructor, leaving impl uninitialized. The nullable type prevents NullPointerException in tests, a worthwhile trade-off.</p><h3>Real-world patterns: Understanding ViewModel usage</h3><p>Understanding the internals helps you recognize patterns and anti-patterns in real-world usage.</p><h4>Pattern 1: Scoped ViewModel sharing</h4><p>ViewModels can be shared across fragments by using the Activity’s ViewModelStore instead of each Fragment’s own store:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac47588b4dbb09e329616d8a8a1e0cee/href">https://medium.com/media/ac47588b4dbb09e329616d8a8a1e0cee/href</a></iframe><p>Both fragments get the same ViewModel instance because they use the same ViewModelStore (the Activity’s). This enables sibling fragment communication through shared state. The internal mechanism:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42493158ffab59c42efb808cdbf703e1/href">https://medium.com/media/42493158ffab59c42efb808cdbf703e1/href</a></iframe><h4>Pattern 2: Custom keys for multiple instances</h4><p>You can have multiple instances of the same ViewModel class by providing custom keys:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f00d6385903fa31e203dd37b67f8ea31/href">https://medium.com/media/f00d6385903fa31e203dd37b67f8ea31/href</a></iframe><p>The key includes the custom string, creating separate cache entries in the ViewModelStore. This is useful for scenarios like managing multiple user profiles or chat conversations simultaneously.</p><h4>Pattern 3: Factory injection with CreationExtras</h4><p>Modern factories are stateless, receiving all dependencies via CreationExtras at creation time:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69bca606dafbfa66bcbc53175577eb54/href">https://medium.com/media/69bca606dafbfa66bcbc53175577eb54/href</a></iframe><p>This allows the factory to be a singleton while the configuration varies per-call, avoiding the need to create a new factory instance for each ViewModel with different dependencies.</p><h4>Anti-pattern: Accessing Context in ViewModel</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a1b40bdbfe317b1af2f837f172de398/href">https://medium.com/media/1a1b40bdbfe317b1af2f837f172de398/href</a></iframe><p>The first approach can leak the Activity because the ViewModel survives configuration changes while holding a reference to the destroyed Activity. Use AndroidViewModel for Application context, or pass Context to individual methods when needed.</p><h4>Anti-pattern: Blocking in onCleared</h4><p>Did you know that onCleared() is called on the main thread? Blocking operations like network shutdown or database cleanup should be offloaded to background threads using addCloseable with coroutines:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39a8b0c9b01a71c918c8fc406c0d2f41/href">https://medium.com/media/39a8b0c9b01a71c918c8fc406c0d2f41/href</a></iframe><h3>Conclusion</h3><p>Jetpack ViewModel’s internal machinery reveals a carefully designed system for lifecycle-aware state management. The ViewModelStore provides simple but effective caching through a retained map, while ViewModelProvider orchestrates creation with thread-safe access and flexible factory support. CreationExtras enables stateless factories by externalizing configuration, and the AutoCloseable integration ensures proper resource cleanup.</p><p>The multiplatform architecture extracts common logic into internal implementation classes, allowing the library to support JVM, Android, iOS, and other platforms. The viewModelScope integration provides automatic coroutine cancellation through the closeable mechanism, with platform-aware dispatcher selection for environments without a main thread.</p><p>If you’re looking to stay sharp with the latest skills, news, technical articles, interview questions, and practical code tips, check out <a href="https://github.com/doveletter/">Dove Letter</a>. And for a deeper dive into interview prep, don’t miss the ultimate Android interview guide: <a href="https://www.android.skydoves.me/">Manifest Android Interview</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2625671eaef8" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/inside-jetpack-viewmodel-internal-mechanisms-and-multiplatform-design-2625671eaef8">Inside Jetpack ViewModel: Internal Mechanisms and Multiplatform Design</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>
    </channel>
</rss>