I have noticed a dramatic decrease in performance ...
# compose
d
I have noticed a dramatic decrease in performance after adding some very large image. I have made it large by mistake, it's actually about 6000x6000 webp image, placed in
drawable-xxxhdpi
, and I render it like so:
Copy code
Box(modifier = Modifier.fillMaxWidth()) {
  Image(
    modifier = Modifier.matchParentSize().padding(19.dp),
    painter = painterResource(id = R.drawable.impossibly_large_image),
  )
  Image(
    painter = painterResource(R.drawable.regular_sized_image)
  )
}
Both images have transparency. I have some pointer input which changes parent composable's state, but this Box is isolated in a separate composable function, not depending on any state. And I have GPU profiler on-screen spikes a quite above 16ms line (see thread for a screenshot). If i remove that "oversized image" it immediately falls below 16ms. My question is: shouldn't Compose pre-scale and somehow cache the Image? Are there some steps to encourage such caching?
(of course making image this large is an error which I will correct, I'm just curious how this works and why performance suffers so badly)
r
The performance impact is most likely due to sampling on the GPU hitting uncached data constantly
Compose doesn't (and probably shouldn't) prescale the image because that would use more memory and there's no way to know what the app intends to do (for instance if you were to zoom in on the image, the prescaled image would have to be dropped and recreated, or abandoned altogether etc.)
This is not specific to compose btw, the same would happen with Views
r
Have you tried loading it up using a library like Coil?
d
The performance impact is most likely due to sampling on the GPU hitting uncached data constantly
By sampling do you mean me running this on-screen profiling? Laggy performance is there even with GPU profiling lines disabled. Or do you mean sampling GPU texture (I'm not that experienced in gpu internals...)
Have you tried loading it up using a library like Coil?
I didn't yet, but thought about this. The problem goes away if I size image correctly, so not sure if I'll go that route, was curious to know why this happens.
By the way, I didn't mention, but pointer input causes another comosable with an image to rotate on top of the Box in the OP and all of them contain alpha channel, so if Romain mentions "sampling" in the sense of GPU drawing, then indeed every frame changes a lot on screen. Though the 6000x6000 image does not rotate and serves as a "base", but still...
r
I meant sampling as in reading pixel data from the bitmap to draw it on screen.