I have a weird issue with recompositions. I have a...
# compose
v
I have a weird issue with recompositions. I have a function with the following metrics, but the function is never skipped even when the parameters don't change:
Copy code
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun MenuButton(
  stable menuOpen: Boolean = @dynamic LiveLiterals$NavBarKt.Boolean$param-menuOpen$fun-MenuButton()
  stable setMenuOpen: Function1<Boolean, Unit>
  defaultFocusRequester: FocusRequester
  stable onWidthChange: Function1<Dp, Unit>
)
The problem goes away from defaultFocusRequester is removed from the parameters, so it's definitely related to that. The object that is passed is the same on every recomposition, but it never skips. Is there a bug in compose metrics reporting the function as skippable? 🤔 Note how the problematic parameter is not marked as stable but the function is still marked skippable in the report.
r
Yeah I wouldn't fully trust the reporting metrics, even though it says skippable it's definitely not, as you said FocusRequester is not marked as
@Stable
I'd love to see someone from Compose team answer why the function is marked as skippable when one of the parameters is not stable, maybe because
FocusRequester
is from a compose library or?
v
I am wondering if the bug is that the function doesn't skip even when the parameter is not explicitly inferred as unstable either. Shouldn't compose compare the identity of the arguments in this case?
I took a brief look at the source of the compiler plugin and it seems that the function is deemed skippable if none of the parameters are explicitly unstable (but I might be wrong on this)
Narrowed it down a bit further. Seems to be that compose cannot infer the stability of any class that has a
MutableVector
member (
FocusRequester
does). I am not sure what the compose compiler infers the stability to be, but it's definitely not stable or unstable 😅
z
MutableVector
is not stable, by definition, and so the compiler can’t infer that anything that uses it is stable.
FocusRequester
should behave as stable though AFAICT, so it is probably a good candidate for overriding the inference.
v
Yeah, we created a stable wrapper class for the time being to deal with this as
FocusRequester
seems to behave like it would be stable
Shouldn't
MutableVector
be inferred as Unstable though? It's currently not inferred as either stable or unstable.
z
honestly not sure
v
Amazing, 🙏 Zach!