在 Compose 中调试重组
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
了解如何在 Jetsnack 中调试性能问题,以及如何在 Compose 中解决此问题。了解为什么使用 lambda 推迟状态读取意味着可以跳过组合。
要点
- Compose 的三个阶段是组合、布局和绘制。
- 如果没有任何变化,Compose 可以跳过相应阶段。有时,Compose 会完全跳过组合以优化性能。
- 您可以使用 lambda 修饰符跳过组合。
- 跳过重新组合有助于减少滚动期间的卡顿。
- Android Studio 中的布局检查器是一款非常有用的工具,可帮助您调试重组问题。
资源
包含本指南的集合
本指南属于以下精选快速入门集合,这些集合涵盖了更广泛的 Android 开发目标:
Compose 基础知识
本系列视频介绍了各种 Compose API,可让您快速了解可用 API 以及如何使用它们。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-06。
[null,null,["最后更新时间 (UTC):2025-02-06。"],[],[],null,["# Debugging recomposition in Compose\n\n\u003cbr /\u003e\n\nA look into debugging a performance issue in Jetsnack and how to fix it in\nCompose. Learn why deferring state reads by using a lambda means composition can\nbe skipped. \n\nKey points\n----------\n\n- The three phases of Compose are composition, layout, and draw.\n- Compose can skip a phase if nothing has changed. Sometimes Compose will entirely skip composition to optimize performance.\n- You can use a lambda modifier can skip composition.\n- Skipping recomposition can help reduce jank during scrolling.\n- The Layout Inspector in Android Studio is a good tool to help you debug recomposition issues.\n\nResources\n---------\n\n- [Blog post](https://goo.gle/3TRm8wv)\n- [Jetsnack on GitHub](https://goo.gle/3D3NCJl)\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Compose basics\n\nThis series of videos introduces various Compose APIs, quickly showing you what's available and how to use them. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/compose-basics) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]