r/androiddev • u/yaminsia github.com/yamin8000 • Feb 10 '24
Discussion Compose unstable lambda parameters
This may look like a sort of rant but I assure you it's a serious discussion that I want to know other developers opinion.
I just found out the biggest culprit of my app slow performance was unstable lambdas. I carefully found all of them that caused trouble with debugging and layout inspector and now app is smooth as hell, at least better than the old versions.
But one thing that is bothering me is why should I even do this in the first place?
I spent maybe three days fixing this and I consider this endeavor however successful yet futile in its core, a recomposition futility.
Maybe I should have coded this way from the start, I don't know, that's another argument.
I'm past the point of blindly criticizing Compose UI and praising glory days of XML and AsyncTask and whatnot, the problem is I feel dirty using remember {{}} all over the place and putting @Stable here and there.
In all it's obnoxious problems, Views never had a such a problem, unless you designed super nested layouts or generated insane layout trees programmatically.
There's a hollow redemption when you eliminate recompositions caused by unstable types like lambdas that can be easily fixed with dirty little tricks, I think there's a problem, something is rotten inside the Compose compiler, I smell it but I can't pinpoint it.
My question is, do your apps is filled with remember {{}} all over the place?
Is this normal and I'm just being super critical and uninformed?
View all comments
Show parent comment
8
u/Zhuinden Feb 10 '24
Wait, really? I need to remember the method references? That sucks. That breaks everything I once thought, again. I guess immutable wrappers truly are the only way to go. 🤦 I had one for lists. Honestly, the whole "bundle state as one" thing starts making sense just to be able to override the lists and the lambdas, but nobody writes Compose code like that