After seeing this post from @marcinmoskala I guess Iโve been making this mistake (not accessing a state via a lambda) all over the place. It seems extremely hard to not make this mistake in fact, because itโs not obvious. Any thoughts? https://x.com/marcinmoskala/status/1967861087576985999/photo/1
๐ 1
r
Robert Jaros
09/16/2025, 12:32 PM
I think the use of phrase "everything" is unfortunate in the first example ๐ There is only one lambda which uses the state, so it is recomposed. But it real apps the layout is more complicated and most of it will not be recomposed.
f
Filip Wiesner
09/16/2025, 12:37 PM
I think it's only relevant for frequently changing values. For example when animating and when the value is passed between multiple layers. Otherwise you don't really need to care about this.
real apps the layout is more complicated
Agreed. Even if you recompose the root element a lot, most of the components inside it will likely be skipped.
Filip Wiesner
09/16/2025, 12:44 PM
Official documentation has dedicated section about this.
But the core takeaway should be the very first sentence:
When a performance issue has been identified, deferring state reads can help
๐ 2
โ๏ธ 2
m
marcinmoskala
09/16/2025, 1:48 PM
I also agree that this optimization is only to optimize in cases where we need to improve performance, and we should do it when we test performance. I need to update this post to make it more clear.