Any idea why a lambda method reference would be co...
# compose
s
Any idea why a lambda method reference would be coming back as "changed" while debugging recomposition, but is marked as stable in compose metrics + calling composable is marked as restartable skippable? Even when i mark the class as @stable, the lambda is showing as changed
🧵 1
a
I think you are misunderstanding "stable". A type being stable or not has nothing to do with whether the value can change. For example, considering
@Composable fun Foo(value: Int)
, as
Int
is stable, this composable function is restartable skippable, but of course the value can change from 0 to 1. The question "Why does a method reference change?" is definitely valid, but it has nothing to do with whether the function type is stable or not. (Btw, all function types are stable.)
âž• 1
s
Thank you for your response! I guess that is my question mainly, why are function references being marked as changed during recomposition? I think I’m trying to understand if the argument(s) the method reference is capturing at the call site have any influence on recomposition, it seemed like those arguments stability didn’t actually show an improvement on recomposition
v
What compiler version are you using? I recently fixed something relating to this and Andrei did some additional fixes after I inadvertently broke something...
The reason it's "changed" is that it's changed. And changed meaning that it is not referentially equal as in
A === B
👌 1
s
This was with compiler version 1.5.6
v
Does your lambda capture some unstable values in its closure?
Something unstable might be a viewmodel or some 3rd party class for example
@Scott Kruse you might want to check the comment I posted in https://issuetracker.google.com/issues/318396527#comment8. It shows how method references work on the bytecode level. In a nutshell, every time you reference a function, it's actually a new class instance on the bytecode level.
The compose compiler creates an optimization around this if you don't reference any unstable values in the method being referenced.