为了测试目的,我设置了一个非常小的项目,在滑动horizontalPager:https://github.com/DaFaack/ComposePerformanceTest时,我看到了很多简陋的框架。
我在启用R8的情况下构建了发布模式。我做错了什么?
当我记录跟踪并在perfetto中查看它时,它向我展示了许多jank:

ViewPager + RecyclerView在XML中的相同设置正在顺利运行。
我试着生成基线配置文件,但没有发现差别,仍然是简陋的框架。
发布于 2022-10-10 11:36:34
而不是使用:
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。
https://stackoverflow.com/questions/73999561
复制相似问题