ประสิทธิภาพของ Jetpack Compose
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Jetpack Compose มีประสิทธิภาพที่ยอดเยี่ยมตั้งแต่เริ่มต้น กำหนดค่าแอปโดยใช้แนวทางปฏิบัติแนะนำเพื่อหลีกเลี่ยงข้อผิดพลาดที่พบได้ทั่วไปและเพิ่มประสิทธิภาพแอปพลิเคชัน Compose
หัวข้อสำคัญ
แนวคิดสําคัญบางส่วนสําหรับประสิทธิภาพในเครื่องมือเขียนมีดังนี้
- ระยะ: การทําความเข้าใจระยะการจัดองค์ประกอบ เลย์เอาต์ และการวาดภาพเป็นสิ่งสําคัญในการเพิ่มประสิทธิภาพวิธีที่เครื่องมือเขียนอัปเดต UI
- โปรไฟล์พื้นฐาน: โปรไฟล์เหล่านี้จะคอมไพล์โค้ดสําคัญไว้ล่วงหน้า ซึ่งทําให้เปิดแอปได้เร็วขึ้นและโต้ตอบได้ราบรื่นขึ้น
- ความเสถียร: เพิ่มความเสถียรของแอปเพื่อข้ามการจัดองค์ประกอบใหม่ที่ไม่จำเป็นอย่างมีประสิทธิภาพมากขึ้น ซึ่งจะช่วยปรับปรุงประสิทธิภาพ
กำหนดค่าแอปอย่างถูกต้อง
หากแอปมีประสิทธิภาพต่ำ แสดงว่าอาจมีปัญหาเกี่ยวกับการกําหนดค่า ขั้นตอนแรกที่ดีคือตรวจสอบตัวเลือกการกําหนดค่าต่อไปนี้
ทําความคุ้นเคยกับชุดเครื่องมือที่พร้อมให้ใช้งานเพื่อช่วยวัดและวิเคราะห์ประสิทธิภาพของแอป Compose
แนวทางปฏิบัติแนะนำ
โปรดคำนึงถึงแนวทางปฏิบัติแนะนำต่อไปนี้เมื่อพัฒนาแอปด้วย Compose
ดูรายละเอียดเพิ่มเติมได้ที่คู่มือแนวทางปฏิบัติแนะนำ
ยอดดู
หากคุณทํางานกับมุมมองแทนการเขียน ให้ดูคําแนะนําปรับปรุงประสิทธิภาพเลย์เอาต์โดยเฉพาะ
แหล่งข้อมูลเพิ่มเติม
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 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-26 UTC"],[],[],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."]]