Are there any optimizations in Compose for the sam...
# compose
s
Are there any optimizations in Compose for the same
CompositionLocal
being retrieved multiple times in a single composition? i.e. I see the Material source code does this with MaterialTheme colors, and default parameters. Is this same pattern safe to copy with 15-20 colors?
s
We cache local map and ignore repeated state reads, I think that's about it
Technically yes But saving it to a local first is always faster
That, or just put colorScheme as a first parameter with default It will be technically unused, but might be faster I would measure the performance of both though, just to compare
s
that's clever.
So I have a small benchmark for this setup already, and I'm seeing strange results based on which I run first. I'll add this and test. Thanks!
@shikasd Quick follow up actually - do you have a recommendation for how to test micro-optimizations like this in Jetpack Compose?
s
I am not sure about the best way to test this, I would probably repeatedly set content to a composable and then reset it to an empty lambda between iterations
For different results depending on the order, you likely are seeing results of JIT Consider disabling it on device or precompiling whole apk with AOT compiler (don't remember specific incantation rn)
s
Thanks for the advice!