https://kotlinlang.org logo
#compose
Title
# compose
r

ribesg

03/01/2024, 2:12 PM
When do you use
derivedStateOf
vs computing every refresh? How much calculation is a lot in a composable?
k

Kacper

03/01/2024, 2:16 PM

https://youtu.be/ahXLwg2JYpc?feature=shared&t=948

- this video is great way to understand when
derivedStateOf
should be used
🌟 1
👌 2
🙏 1
s

Stylianos Gakis

03/01/2024, 2:17 PM
I've always seen people say that using derivedStateOf is orders of magnitude more expensive than just doing the calculation itself. So it's only worth it if the rate of change between the inputs and the output differ by a lot. "A lot" is arbitrary, but I really take it as a case by case basis. For example observing scroll state (changes every frame) and deriving something out of that is for example often the right approach. But if you share some example you got in mind it's gonna be easier to discuss.
r

ribesg

03/01/2024, 2:24 PM
Thanks for that video, the explanation is perfectly clear. It's really more like a
distinct
. In my case I was just implementing a template String of the quite-big kind (with dozens of variables) and was wondering what the correct way of handling that was: a big remember with a lot of keys, or maybe something else I didn't really understand like derivedStateOf, or maybe nothing and computing that String isn't that heavy