繁体   English   中英

在 Jetpack Compose 中使用 HorizontalPager + LazyVerticalGrid 时性能不佳

[英]Performance is bad when using HorizontalPager + LazyVerticalGrid in Jetpack Compose

我设置了一个非常小的项目用于测试目的,并且在滑动 horizontalPager 时看到很多卡顿帧: https://github.com/DaFaack/ComposePerformanceTest

我在启用 R8 的情况下以发布模式构建。 我究竟做错了什么?

当我记录跟踪并在 perfetto 中查看它时,它显示了很多卡顿: 在此处输入图像描述

XML 中与 ViewPager + RecyclerView 相同的设置运行顺利

我尝试生成基线配置文件,但看不出有什么区别,仍然是卡顿的帧

而不是使用:

LazyVerticalGrid(columns = GridCells.Fixed(5), content = {
        items(40) {
            ImageItem(imageUrl, name)
        }
    })

利用:

(0..40).forEach { it ->
    item(key: /*Create an constant key for each item*/) {
        ImageItem(imageUrl, name)
    }
}

我在某处读到,在列表上使用 foreach 可以大大提高性能以及自定义键。 此外,尝试在任何可能的情况下使用 fastForEach。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM