[英]Performance is bad when using HorizontalPager + LazyVerticalGrid in Jetpack Compose
I setup a really small project for testing purposes and I see a lot of janky frames when swiping the horizontalPager: https://github.com/DaFaack/ComposePerformanceTest我设置了一个非常小的项目用于测试目的,并且在滑动 horizontalPager 时看到很多卡顿帧: https://github.com/DaFaack/ComposePerformanceTest
I build in release mode with R8 enabled.我在启用 R8 的情况下以发布模式构建。 What am I doing wrong?
我究竟做错了什么?
When I record the trace and view it in perfetto it shows me a lot of jank:当我记录跟踪并在 perfetto 中查看它时,它显示了很多卡顿:
The same setup in XML with ViewPager + RecyclerView is running smoothly XML 中与 ViewPager + RecyclerView 相同的设置运行顺利
I tried generating baseline profiles but see no difference, still janky frames我尝试生成基线配置文件,但看不出有什么区别,仍然是卡顿的帧
rather than using:而不是使用:
LazyVerticalGrid(columns = GridCells.Fixed(5), content = {
items(40) {
ImageItem(imageUrl, name)
}
})
use:利用:
(0..40).forEach { it ->
item(key: /*Create an constant key for each item*/) {
ImageItem(imageUrl, name)
}
}
I have read somewhere that using foreach on lists greatly increases performance along with custom keys.我在某处读到,在列表上使用 foreach 可以大大提高性能以及自定义键。 Additionally, try to use fastForEach in any possible scenario.
此外,尝试在任何可能的情况下使用 fastForEach。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.