简体   繁体   English

Jetpack Compose 惰性列性能

[英]Jetpack Compose lazycolumn performance

I'm new to jetpack compose and learning it from code of JetpackCompose Basics so I have found in the create a performant lazy list我是 jetpack compose 的新手,并从JetpackCompose Basics的代码中学习它,所以我在创建高性能惰性列表中找到了

Note: LazyColumn doesn't recycle its children like RecyclerView .注意: LazyColumn 不像RecyclerView那样回收它的孩子。 It emits new Composables as you scroll through it and is still performant, as emitting Composables is relatively cheap compared to instantiating Android Views.当您滚动浏览它时,它会发出新的Composables并且仍然是高性能的,因为与实例化 Android 视图相比,发出Composables相对便宜。

so how emitting new composable is cheap and performant, and then why not to just using column and compose the whole list for one time instead of keep emitting composable items while scrolling even if the emitting composables is only the items visible by layout那么如何发射新的可组合物既便宜又高效,那么为什么不只使用列并组合整个列表一次,而不是在滚动时继续发射可组合项目,即使发射的可composables项目只是布局可见的项目

Update: if the visible items is 10, so before user scroll the items from 0 to 9 is visible and has been rendered, now the user has scrolled up and the visible items from 5 to 14, is jetpack compose removed the 5 items that have been previously rendered and if user scroll down, they will be recomposed or jetpack compose keep all rendered views in memory no matter if it visible or not更新:如果可见项目是 10,那么在用户滚动从 0 到 9 的项目之前是可见的并且已经被渲染,现在用户已经向上滚动并且可见项目从 5 到 14,jetpack compose 删除了 5 个项目之前已渲染,如果用户向下滚动,它们将被重新组合或 jetpack 组合将所有渲染视图保留在 memory 中,无论它是否可见

Because there's a limit to the definition of "cheap", but no limit to how big a list can be.因为“便宜”的定义是有限制的,但列表可以有多大是没有限制的。 It may be cheap to output 100-200 composables (which I'm not convinced of, but lets say so for the sake of argument). output 100-200 可组合物可能很便宜(我不相信,但为了争论,可以这么说)。 It isn't cheap to output 10K of them. output 10K 并不便宜。 Which a list of results backed by a DB could easily be.由数据库支持的结果列表很容易得到。

So you still don't want to output everything all time time.所以你仍然不想一直 output 一切。 But it may be relatively cheap to output everything a user would reasonably scroll to, because nobody goes to the end of a 10K list.但是对于用户可以合理滚动到的所有内容,output 可能相对便宜,因为没有人会走到 10K 列表的末尾。 Thus making it a reasonable compromise based on common user behavior.从而使其成为基于常见用户行为的合理折衷方案。 You'd lose performance as they scroll further down the page, but the percentage of users who do that is small enough you may not care.当他们进一步向下滚动页面时,您会失去性能,但是这样做的用户百分比足够小,您可能不在乎。

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

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