# compose

Guy Bieber

10/16/2020, 7:41 PM
I have a colleague who zstacks all their screens and changes what is in front. I typically just switch what is being rendered in a composable with a if or case statement. Is doing stacking a best practice for compose?

Alexandre Elias [G]

10/17/2020, 2:26 AM
if/case statements are the recommended best practice for Compose. that is what we are using in all our sample apps and optimizing Compose's performance for
👍 1
if the idea behind the zstacking approach is to cache/preload expensive data for performance reasons, the best practice would be to hoist up that state to a parent Composable of the screens so that it's `remember`ed even if the child screen falls into an "else" block
👍 1
Compose doesn't have much in the way of optimizations to avoid doing unnecessary work for z-occluded composables, so having tons of stacked invisible screens could cause more performance problems than it solves
👍 1