I'm looking for a way to improve the performance o...
# compose
s
I'm looking for a way to improve the performance of
AnimatedVisibility
with a lot of content. In the UI I build you can expand a lot of controls there and the first time it lags visibly. ChatGPT recommended to pre-warm the composable by rendering the content first in a Box with size 0 or alpha 0, but that didn't really help. It also came up with a non-working SubComposeLayout hack. What's the proper way to pre-warm content in
AnimatedVisibility
so it doesn't lag?
đź‘€ 1
z
Did you profile to see why it’s actually laggy?
s
Nope, I guess because the Composable inside has a lot of controls / stuff to render
I'm looking for an general approach to pre-warm composables inside AnimatedVisibility
f
Does the lag also happens on a release build?
s
Yes. That’s where I noticed it. It’s not visible on my MacBook M1 as that renders fast enough, but my Windows machine has a noticeable lag. There must be a proper way to pre-render / pre-warm this animation… After the first time it’s fast on the machine. Just jot the first time the user clicks.
z
Do you use SubcomposeLayout? Asking because I had a very similar situation recently where I even tried to pre-warm my composables. At the end of the day, Scaffold (M3) with SubcomposeLayout was what caused the lag for me. The screen in question is very complicated with a ton of composables, yet it does not lag any longer. Maybe that's worth looking into!
s
So
SubcomposeLayout
is the solution to pre-warm? ChatGPT suggested that, but all code it generated was broken. So I would need to find a good sample code how to use it.
z
I meant that if you're already using SubcomposeLayout, if you can manage without then that might fix the performance issues! It did for me at least. It seems that there's an almost exponential performance dropoff when SubcomposeLayout is involved, but I haven't made any scientific measurements yet!
s
I don’t use that. I have a simple AnimatedVisibility … and I am looking for ways to make that more performant.