Performance & Profiling: Recomposition Optimization with Live Metrics | Kotlin Desktop #19

22views
2likes
0
31:39
T
Taught by Celeste AI - AI Coding Coach
View on YouTube
Description
Learn Compose recomposition optimization in Kotlin Desktop! We build a Performance Lab — a product catalog with 200 items, search, sorting, and a real-time ticker. A toggle switches between Naive (5 anti-patterns) and Optimized (5 fixes) implementations. A MetricsPanel shows live recomposition counts, making the performance difference dramatically visible. What You'll Learn: - @Immutable annotation to mark data classes as stable for Compose skip optimization - derivedStateOf to wrap computed values that only recompute when their specific inputs change - key() parameter in LazyColumn for identity-based diffing instead of positional matching - remember for lambda callbacks to avoid creating new instances every recomposition - remember(key) for caching formatted strings and computed values - Isolating volatile state (tickers) into dedicated composables to prevent cascading recomposition - SideEffect for tracking recomposition counts after every successful composition - ConcurrentHashMap with AtomicInteger for thread-safe recomposition counting - SegmentedButtonRow for clean mode toggling between Naive and Optimized implementations - Real-time MetricsPanel with color-coded severity (green/orange/red) Timestamps: 0:00 - Introduction 0:15 - Preview: Performance Lab App 0:45 - Project Setup & Product Models 4:31 - Recomposition Tracker & Metrics Panel 8:57 - Naive Implementation (5 Anti-Patterns) 17:23 - Optimized Implementation (5 Fixes) 23:39 - AppContent + Main & Compile 28:34 - Live Demo: Naive vs Optimized 29:39 - Recap & Key Takeaways 30:39 - Thanks for Watching Key Takeaways: 1. @Immutable / @Stable — Annotate data classes so Compose can safely skip recomposition checks 2. derivedStateOf — Wrap computed values so they only recompute when their specific inputs change 3. key() in LazyColumn — Pass unique IDs for identity-based diffing instead of positional matching 4. Remember Lambdas — Extract callbacks with remember to avoid new instances every recomposition 5. Isolate Volatile State — Put tickers and counters in their own composable to prevent cascading recomposition Previous Lesson: Lesson 18: System Integration — System Toolbox with Clipboard, Commands & Notifications https://youtube.com/... Next Lesson: Lesson 20: (coming soon) Tech Stack: Kotlin 2.1, Compose Multiplatform 1.7.3, Material3 Material Icons Extended, Compose Runtime (@Immutable, derivedStateOf, SideEffect) Gradle 8.10, JVM 17+ Source Code: https://github.com/GoCelesteAI/kotlin_desktop_performance_lab Taught by CelesteAI If you found this helpful, please like and subscribe for more Kotlin Desktop tutorials! #kotlin #compose #desktop #material3 #performance #recomposition #optimization #immutable #derivedstateof #lazycolumn #profiling #tutorial #programming Tags kotlin, compose multiplatform, compose desktop, material3, performance, recomposition, optimization, immutable, stable, derivedstateof, lazycolumn, key, remember, jetbrains compose, kotlin tutorial, desktop app, jvm, composable, performance lab, profiling Category: Science & Technology | Visibility: Public

Tags

kotlincompose multiplatformcompose desktopmaterial3performancerecompositionoptimizationimmutablestablederivedstateoflazycolumnkeyrememberjetbrains composekotlin tutorial
Back to tutorials

Duration

31:39

Published

February 25, 2026

Added to Codegiz

March 15, 2026

Open in YouTube