Compose のフェーズとパフォーマンス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Compose がフレームを更新する際、次の 3 つのフェーズを経由します。
- コンポジション: Compose は表示する内容を決定します。コンポーズ可能な関数を実行し、UI ツリーを構築します。
- レイアウト: Compose は、UI ツリー内の各要素のサイズと配置を決定します。
- 描画: Compose は実際に個々の UI 要素をレンダリングします。
Compose は、必要ない場合にこれらのフェーズのいずれかをインテリジェントにスキップできます。たとえば、1 つのグラフィック要素が、同じサイズの 2 つのアイコン間で入れ替わるとします。この要素はサイズが変更されず、UI ツリーの要素が追加または削除されていないため、Compose はコンポジション フェーズとレイアウト フェーズをスキップして、この 1 つの要素を再描画できます。
ただし、コーディングミスがあると、Compose が安全にスキップできるフェーズを把握するのが難しくなる可能性があります。その場合、Compose は 3 つのフェーズすべてを実行するため、UI の速度が低下する可能性があります。したがって、パフォーマンスに関するベスト プラクティスの多くは、Compose が不要なフェーズをスキップできるようにすることです。
詳しくは、Jetpack Compose のフェーズのガイドをご覧ください。
一般的な原則
一般的に、パフォーマンスを向上させるには、次の 2 つの大原則に従う必要があります。
- 可能な限り、コンポーズ可能な関数から計算を移動します。
UI が変更されるたびに、コンポーズ可能な関数の再実行が必要になる場合があります。コンポーザブルに追加したコードは、アニメーションのフレームごとに再実行されます。コンポーザブルのコードは、UI の構築に必要なもののみに制限します。
- 状態の読み取りを可能な限り延期する。状態の読み取りを子コンポーザブルまたは後のフェーズに移動することで、再コンポーズを最小限に抑えるか、コンポジション フェーズを完全にスキップできます。これを行うには、頻繁に変化する状態については状態値の代わりにラムダ関数を渡し、頻繁に変化する状態を渡すときはラムダベースの修飾子を優先します。この手法の例については、ベスト プラクティスに従うの可能な限り読み取りを延期するのセクションをご覧ください。
その他のリソース
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","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-27 UTC。"],[],[],null,["# Compose phases and performance\n\nWhen Compose updates a frame, it goes through three phases:\n\n- **Composition:** Compose determines *what* to show. It runs composable functions and builds the UI tree.\n- **Layout:** Compose determines the size and placement of each element in the UI tree.\n- **Drawing:** Compose actually *renders* the individual UI elements.\n\nCompose can intelligently skip any of those phases if they aren't needed. For\nexample, suppose a single graphic element swaps between two icons of the same\nsize. Since this element isn't changing size, and no elements of the UI tree are\nbeing added or removed, Compose can skip over the composition and layout phases\nand redraw this one element.\n\nHowever, coding mistakes can make it hard for Compose to know which phases it\ncan safely skip, in which case Compose runs all three phases, which can slow\ndown your UI. So, many of the performance best practices are to help Compose\nskip the phases it doesn't need to do.\n\nFor more information, see the [Jetpack Compose Phases](/develop/ui/compose/phases) guide.\n\nGeneral principles\n------------------\n\nThere are a couple of broad principles to follow that can improve performance in\ngeneral:\n\n- **Whenever possible, move calculations out of your composable functions.** Composable functions might need to be rerun whenever the UI changes. Any code you put in the composable gets re-executed, potentially for every frame of an animation. Limit the composable's code to only what it needs to build the UI.\n- **Defer state reads for as long as possible.** By moving state reading to a child composable or a later phase, you can minimize recomposition or skip the composition phase entirely. You can do this by passing lambda functions instead of the state value for frequently changing state and by preferring lambda-based modifiers when you pass in frequently changing state. You can see an example of this technique in the [Defer reads as long as possible](/develop/ui/compose/performance/bestpractices#defer-reads) section of [Follow best practices](/develop/ui/compose/performance/bestpractices).\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."]]