Compose 단계 및 성능
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Compose에서 프레임을 업데이트할 때는 다음 세 단계를 거칩니다.
- 컴포지션: Compose는 표시할 내용을 결정합니다. 구성 가능한 함수를 실행하고 UI 트리를 빌드합니다.
- 레이아웃: Compose는 UI 트리에 있는 각 요소의 크기와 배치를 결정합니다.
- 그리기: Compose는 실제로 개별 UI 요소를 렌더링합니다.
Compose는 필요하지 않으면 이러한 단계를 지능적으로 건너뛸 수 있습니다. 예를 들어 단일 그래픽 요소가 크기가 같은 두 아이콘 간에 전환된다고 가정해 보겠습니다. 이 요소는 크기가 변경되지 않고 UI 트리의 요소가 추가 또는 삭제되지 않으므로 Compose는 컴포지션 단계와 레이아웃 단계를 건너뛰고 이 요소 하나를 다시 그릴 수 있습니다.
그러나 코딩 오류로 인해 Compose가 안전하게 건너뛸 수 있는 단계를 알기 어려울 수 있습니다. 이 경우 Compose가 세 단계를 모두 실행하여 UI 속도가 느려질 수 있습니다. 따라서 성능 권장사항은 Compose가 필요하지 않은 단계를 건너뛰도록 돕는 것입니다.
자세한 내용은 Jetpack Compose 단계 가이드를 참고하세요.
일반 원칙
일반적으로 성능을 개선할 수 있는 몇 가지 광범위한 원칙이 있습니다.
- 가능하다면 구성 가능한 함수 외부로 계산을 이동하세요.
구성 가능한 함수는 UI가 변경될 때마다 다시 실행해야 할 수 있습니다. 컴포저블에 넣은 코드는 애니메이션의 모든 프레임에서 다시 실행됩니다. 컴포저블의 코드를 UI를 빌드하는 데 필요한 항목으로만 제한합니다.
- 상태 읽기를 최대한 오래 연기합니다. 상태 읽기를 하위 컴포저블 또는 이후 단계로 이동하여 리컴포지션을 최소화하거나 컴포지션 단계를 완전히 건너뛸 수 있습니다. 자주 변경되는 상태의 상태 값 대신 람다 함수를 전달하고, 자주 변경되는 상태를 전달할 때 람다 기반 수정자를 선호하여 이를 실행할 수 있습니다. 권장사항 준수의 최대한 읽기 연기 섹션에서 이 기법의 예를 확인할 수 있습니다.
추가 리소스
- 앱 성능 가이드: Android에서 성능을 개선하기 위한 권장사항, 라이브러리, 도구를 살펴봅니다.
- 성능 검사: 앱 성능을 검사합니다.
- 벤치마킹: 앱 성능을 벤치마킹합니다.
- 앱 시작: 앱 시작을 최적화합니다.
- 기준 프로필: 기준 프로필을 이해합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 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."]]