Jetpack Compose 效能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Jetpack Compose 提供立即可用的卓越效能。按照最佳做法設定應用程式,以避免常見錯誤,並將 Compose 應用程式效能最佳化。
核心概念
以下是 Compose 中與效能相關的幾個重要概念:
- 階段:瞭解組合、版面配置和繪圖階段,是最佳化 Compose 更新 UI 方式的關鍵。
- 基準設定檔:這些設定檔會預先編譯基本程式碼,可加快應用程式啟動速度,並更順暢地進行互動。
- 穩定性:提升應用程式的穩定性,以便更有效率地略過不必要的重組作業,進而改善效能。
正確設定應用程式
如果應用程式效能不佳,可能是設定問題所致。第一步是查看下列設定選項:
熟悉有助於評估及分析 Compose 應用程式效能的工具套件。
最佳做法
使用 Compose 開發應用程式時,請謹記以下最佳做法:
詳情請參閱最佳做法指南。
觀看次數
如果使用的是檢視畫面 (而非 Compose),請參閱專屬的「改善版面配置效能」指南。
其他資源
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Jetpack Compose Performance\n\nJetpack Compose delivers excellent performance out of the box. Configure your\napp using best practices to avoid common pitfalls and optimize your Compose\napplication's performance.\n\nKey concepts\n------------\n\nThese are some of the key concepts for performance in Compose:\n\n- **[Phases](/develop/ui/compose/performance/phases):** Understanding the composition, layout, and drawing phases is crucial for optimizing how Compose updates your UI.\n- **[Baseline Profiles](/develop/ui/compose/performance/baseline-profiles):** These profiles precompile essential code, leading to faster app launches and smoother interactions.\n- **[Stability](/develop/ui/compose/performance/stability):** Increase the stability of your app to more efficiently skip unnecessary recompositions, improving performance.\n\nProperly configure your app\n---------------------------\n\nIf your app is performing poorly, there might be a configuration problem. A good\nfirst step is to check the following configuration options:\n\n- **Build in Release Mode with R8:** Try running your app in [release\n mode](/studio/run#changing-variant). Debug mode is useful for spotting many problems, but it imposes a performance cost and can make it hard to spot other issues. You should also [enable optimizing and shrinking](/build/shrink-code#enable) with the R8 compiler to ensure a performant and efficient release build.\n- **Use Baseline Profiles:** Baseline Profiles improve performance by precompiling code for critical user journeys. Compose includes a default profile, but ideally, you should create an app-specific one as well. [Learn\n more about Baseline Profiles in the general Android performance docs](/topic/performance/baselineprofiles/overview)\n\nTools\n-----\n\nFamiliarize yourself with the suite of [tools](/develop/ui/compose/performance/tooling) available to help you measure\nand analyze your Compose app's performance.\n\nBest Practices\n--------------\n\nWhen developing your app with Compose, keep these best practices in mind:\n\n- **[Avoid expensive calculations](/develop/ui/compose/performance/bestpractices#use-remember):** Use `remember` to cache the results of expensive calculations.\n- **[Help lazy layouts](/develop/ui/compose/performance/bestpractices#use-lazylist-keys):** Provide stable keys to lazy layouts using the `key` parameter to minimize unnecessary recompositions.\n- **[Limit unnecessary recompositions](/develop/ui/compose/performance/bestpractices#use-derivedstateof):** Use `derivedStateOf` to limit recompositions when rapidly changing state.\n- **[Defer state reads](/develop/ui/compose/performance/bestpractices#defer-reads):** Defer state reads as long as possible by wrapping them in lambda functions.\n- **[Use lambda modifiers for changing state](/develop/ui/compose/performance/bestpractices#defer-reads):** Use lambda-based modifiers like `Modifier.offset { ... }` for frequently changing state variables.\n- **[Avoid backwards writes](/develop/ui/compose/performance/bestpractices#avoid-backwards):** Never write to state that has already been read in a composable.\n\nFor more details, see the [best practices](/develop/ui/compose/performance/bestpractices) guide.\n\nViews\n-----\n\nIf you are working with views instead of Compose, see the dedicated [Improve\nlayout performance](/develop/ui/views/layout/improving-layouts) guide.\n\nAdditional Resources\n--------------------\n\n- **[App performance guide](/topic/performance/overview)**: Discover best practices, libraries, and tools to improve performance on Android.\n- **[Inspect Performance](/topic/performance/inspecting-overview):** Inspect app performance.\n- **[Benchmarking](/topic/performance/benchmarking/benchmarking-overview):** Benchmark app performance.\n- **[App startup](/topic/performance/appstartup/analysis-optimization):** Optimize app startup.\n- **[Baseline profiles](/baseline-profiles):** Understand baseline profiles."]]