android-compose-performance

📁 hexoplon/skills 📅 4 days ago
1
总安装量
1
周安装量
#44579
全站排名
安装命令
npx skills add https://github.com/hexoplon/skills --skill android-compose-performance

Agent 安装分布

amp 1
opencode 1
kimi-cli 1
codex 1
github-copilot 1
gemini-cli 1

Skill 文档

Android Compose & Kotlin Performance

Workflow

  1. Identify the problem area:

  2. Apply targeted fixes using the patterns in the relevant reference file.

  3. Verify in release mode — debug builds disable Compose compiler optimizations and skippability, making profiling unreliable.

Quick Reference: Most Common Mistakes

Compose

  • Reading state in parent when only child needs it — pass () -> T lambdas instead
  • Using List/Map/Set params (unstable) — use kotlinx.collections.immutable or @Immutable
  • Missing key in LazyColumn/LazyRow items
  • Using Modifier.offset(x, y) instead of Modifier.offset { IntOffset(x, y) } for animated values
  • Sorting/filtering inside composables instead of ViewModel
  • Profiling in debug builds

Coroutines

  • Using GlobalScope instead of viewModelScope/lifecycleScope
  • Using synchronized/ReentrantLock instead of Mutex.withLock in coroutine code
  • Collecting StateFlow without repeatOnLifecycle or collectAsStateWithLifecycle()
  • Using Channel when SharedFlow is appropriate (one-to-many) or vice versa
  • Running IO work on Dispatchers.Default or Dispatchers.Main

Recommended Architecture

  • ViewModel: MutableStateFlow for UI state, exposed as StateFlow. Logic in viewModelScope.
  • Repository/data layer: withContext(Dispatchers.IO) for disk/network. Expose Flow.
  • Compose UI: Collect via collectAsStateWithLifecycle(). Defer reads via lambdas. Use stable types. Provide keys to lazy layouts.
  • Cross-coroutine: Channel for one-to-one delivery, SharedFlow for one-to-many broadcast.
  • Synchronization: Mutex.withLock over synchronized in coroutine code.