1

Jetpack Compose version: '1.1.0' and Jetpack Compose component used: androidx.compose.* (base components_ Android Studio Build: 2021.2.1 Kotlin version:1.6.10

I have simple code inside activity. When i start App and start scroll with speed, i see scrolling lags :( What is wrong with this code?

    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
        TestComposeTheme {
            val list = (1..300).toList()
            LazyColumn(
                Modifier.fillMaxSize(),
            ) {
                items(list) { item ->
                    SomeItem(
                        text = item.toString(),
                        clickListener = {}
                    )
                    Spacer(modifier = Modifier.height(16.dp))
                }
            }
        }
    }
}


@Composable
fun SomeItem(
    text: String,
    clickListener: (String) -> Unit
) {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .height(64.dp)
            .background(Color.LightGray)
            .clickable { clickListener.invoke(text) }
    ) {
        Icon(painter = painterResource(id = R.drawable.ic_back), contentDescription = "")
        Spacer(modifier = Modifier.height(8.dp))
        Text(
            modifier = Modifier,
            text = text
        )

    }
}
user2291961
  • 11
  • 1
  • 2
  • There is nothing wrong with the code. Performance should only be measured on release builds (preferably with Proguard), and on initial install the app will be a bit janky because the code is being interpreted, not compiled. – Francesc May 18 '22 at 15:29
  • Is it possible to precompile code? – user2291961 May 18 '22 at 16:07
  • You can provide a Baseline Profile with your APK, see this: https://developer.android.com/topic/performance/baselineprofiles – Francesc May 18 '22 at 16:34

1 Answers1

2

I also got laggy scroll when using lazycolumn (I'm migrating my Native Android project to Jetpack Compose, so i used "ComposeView in XML". Its not a pure Compose project.)

I don't know why the issue coming(Tried with release build also ), but i solved with below code.

Instead of using "LazyColumn", i used "rememberScrollState() with Column"

        Column(
            modifier = Modifier
                .verticalScroll(rememberScrollState())
                .padding(5.dp)
        ) {
            list.forEachIndexed { i, _ ->
                ShowItems(i)
            }
        }

Hope this will help some one. Please attach if better Answer there, I will also update my project.

**

EDIT :: UPDATE

** In release Build, somewhat better then DEBUG app.

  • The above case is only use for less amount of data. If we have large data there is no option we have to use "LazyColumn".
Dev007
  • 222
  • 2
  • 9
  • I have the same issue and your solution works. But I´m using paging3 and I need LazyColumn.... – Patrick Sep 28 '22 at 10:32
  • 2
    @Patrick Samething still I'm facing same laggy.in somecase i need to use LazyColumn (Paging3) or a very large volume of data. But what i found, in DEBUG only getting Extreme Laggy, in Release build some what better then Debug. Give it a Try Once. – Dev007 Sep 28 '22 at 17:58
  • 1
    Yeah. In release mode works better. I don't love it anyway. – Patrick Sep 30 '22 at 06:11