Aşamaları ve performansı oluşturma
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Oluşturma bir kareyi güncellediğinde üç aşamadan geçer:
- Beste: Oluştur, nelerin gösterileceğini belirler. composable işlevlerini çalıştırır ve kullanıcı arayüzü ağacını oluşturur.
- Düzen: Oluştur, kullanıcı arayüzü ağacındaki her bir öğenin boyutunu ve yerleşimini belirler.
- Çizim: Oluştur işlevi aslında bağımsız kullanıcı arayüzü öğelerini oluşturur.
Oluşturma işlemi, gerekli olmadığı sürece bu aşamaların herhangi birini akıllı bir şekilde atlayabilir. Örneğin, tek bir grafik öğesinin aynı boyuttaki iki simge arasında geçiş yaptığını varsayalım. Bu öğenin boyutu değişmediğinden ve kullanıcı arayüzü ağacında hiçbir öğe eklenmediğinden veya kaldırılmadığından Compose oluşturma ve düzen aşamalarını atlayıp bu tek öğeyi yeniden çizebilir.
Ancak, kodlama hataları, Compose'un hangi aşamaları güvenli bir şekilde atlayabileceğini bilmesini zorlaştırabilir. Bu durumda, Compose üç aşamayı da çalıştırır ve bu durum kullanıcı arayüzünüzü yavaşlatabilir. Bu nedenle, en iyi performans uygulamalarının çoğu, Compose'un yapması gerekmeyen aşamaları atlamasına yardımcı olur.
Daha fazla bilgi için Jetpack Oluşturma Aşamaları kılavuzuna bakın.
Genel ilkeler
Genel olarak performansı artırabilecek birkaç genel ilke vardır:
- Mümkün olduğunda, hesaplamaları composable işlevlerinizin dışına taşıyın.
Kullanıcı arayüzü değiştiğinde composable işlevlerin yeniden çalıştırılması gerekebilir. composable'a yerleştirdiğiniz tüm kodlar, potansiyel olarak bir animasyonun her karesinde yeniden yürütülür. composable'ın kodunu yalnızca kullanıcı arayüzünü derlemek için gereken kodla sınırlandırın.
- Durum okumalarını mümkün olduğu kadar erteleyin. Durum okumasını "child composable" veya daha sonraki bir aşamaya taşıyarak yeniden
kompozisyonu en aza indirebilir ya da beste aşamasını tamamen atlayabilirsiniz. Bunu, sık sık değişen durum için durum değeri yerine lambda işlevlerini ileterek ve sık sık değişen durumlarda lambda tabanlı değiştiricileri tercih ederek yapabilirsiniz. Bu tekniğin bir örneğini En iyi uygulamaları takip etme başlıklı makalenin Mümkün olduğunca uzun süre okumaları ertele bölümünde görebilirsiniz.
Ek Kaynaklar
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-27 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 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."]]