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

hfhbd

02/09/2022, 8:09 PM
z

Zach Klippenstein (he/him) [MOD]

02/09/2022, 8:10 PM
Are there specific hidden costs you’re wondering about, or just if there are any in general?
h

hfhbd

02/09/2022, 8:10 PM
General
z

Zach Klippenstein (he/him) [MOD]

02/09/2022, 8:11 PM
Probably the biggest one would be if you’re providing a static composition local that changes over time, because it will require every composable in the content to recompose.
I’m not aware of any significant costs to simply providing a value otherwise. Reading a non-static composition local is slightly more expensive than reading a static one, because of the read tracking involved, but it’s not something to be worried about unless your benchmarks show otherwise.
h

hfhbd

02/09/2022, 8:14 PM
So if I update the value "during" recomposition, it will recompose the sub content too. yeah, makes sense
I think, I just have to test it 😄
Do you know a good compose profiler/benchmark tool? Besides simple measuring the time
r

romainguy

02/09/2022, 8:20 PM
The Jetpack Benchmark library is the best way to write benchmarks
It tries to ensure consistent measurements in various ways
Note that beyond performance questions,
CompositionLocalProvider
can be a “dangerous” tool as it effectively create somewhat invisible dependencies
Which can make reusing composables more difficult/less obious
h

hfhbd

02/09/2022, 8:23 PM
I know, you should avoid it. My usecase is subtree based relative routing.
Thanks for sharing Jetpack Benchmark, but is it possible to measure non ui composables?
r

romainguy

02/09/2022, 8:38 PM
Yes, esp. with microbenchmarks
2 Views