Sam
04/13/2025, 8:17 PMChoreographer: Skipped 69 frames! The application may be doing too much work on its main thread.
). I get the initial frame drops when the code is just being JITed, however, it doesn't seem to recover at all (testing in Android 12L). Can anyone give some pointers as to what is happening in the debug version?Sam
04/13/2025, 8:17 PM@Composable
fun LazyGridContainer(modifier: Modifier = Modifier) {
val images = remember { mutableStateListOf<Image>() }
LaunchedEffect(Unit) {
val newImages = (1..10000).map { Image("Title $it", "<https://picsum.photos/200/300>") }
images.addAll(newImages)
}
LazyGridComposable(images, modifier)
}
@Composable
private fun LazyGridComposable(images: List<Image>, modifier: Modifier = Modifier) {
LazyVerticalGrid(
columns = GridCells.Adaptive(110.dp),
modifier = modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
items(images.size) { index ->
GridItem(images[index])
}
}
}
@Composable
private fun GridItem(image: Image, modifier: Modifier = Modifier) {
Box(
modifier = modifier
.size(100.dp)
.background(Color.Gray),
contentAlignment = Alignment.BottomCenter
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(image.url)
.memoryCachePolicy(CachePolicy.DISABLED)
.diskCachePolicy(CachePolicy.DISABLED)
.build(),
contentDescription = null,
modifier = Modifier.fillMaxSize()
)
Text(text = image.title, color = Color.Red)
}
}
Sam
04/13/2025, 8:18 PMSergey Y.
04/13/2025, 8:25 PMSergey Y.
04/13/2025, 9:20 PMAsyncImage
doesn’t resize bitmaps by default, so you need to specify it manually. However, SubComposeAsyncImage
does resize them automatically, if I’m not mistaken.rememberAsyncImagePainter
definitely does not resize images before displaying them.Sam
04/13/2025, 9:58 PMSam
04/13/2025, 9:59 PMPrefer using AsyncImage in most cases. It correctly determines the size your image should be loaded at based on the constraints of the composable and the provided ContentScale.
Sergey Y.
04/13/2025, 10:10 PMIt is debug. Trying to understand why speed of scroll matters over here.First time with Compose? 😅 TLDR: Debug builds are slow because they add debugging overhead and disable most compiler and runtime (JIT/AOT) optimizations. Release builds with R8 are fast because they include full build-time (compiler, R8) and runtime (JIT/AOT) optimizations. Measure performance on release builds only for accurate results.