https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

10/19/2023, 9:10 PM
Do people here go out of their way to ensure stability of params, etc? I've shipped 5 fully compose apps over the past 2 years. Millions of users. I have never once written a
@Stable
annotation or used immutable collections. Never had any perf issues and I've had some complex layouts I've had to implement. Is it just me? Should I be using
@stable
?
☝️ 1
☝🏼 1
p

Pablichjenkov

10/19/2023, 9:15 PM
Not too worried about that either. No issues/complaints reported so far. 2 Apps different companies with over 1 million each.
t

Travis Griggs

10/19/2023, 10:07 PM
Wow. what kinds of apps are you guys releasing that are getting 1 million users?? I work in Ag Tech. I have many many many fewer users 😄
f

Francesc

10/19/2023, 10:47 PM
there is a middle point between "I don't care about stability" and "everything must be stable". While attempting to have everything stable can add significant overhead, at the same time I think that some effort should be put into it, at least for the low-hanging fruit fixes. Saying "I never had any performance issues" doesn't mean anything other than being anecdotal; having some benchmarking so that there is a basis to determine whether the performance is good enough or not would be the way to go about it. If your benchmarks show an issue, then it'd be worth to delve deeper and figure out what can be improved.
2
p

Pablichjenkov

10/19/2023, 10:56 PM
Medical devices and Cruise line
Yeah I agree it is not like "I don't care about performance". I try the best practices but things like marking everything Stable is a pain. And, also, in some cases still has the risk of someone mutating it accidentally. In which case the UI won't update. I prefer losing a bit of performance but guarantee that every time the states update it is reflected on the screen. Recently I was talking with a colleague about that. The security and confidence of having every single state change reflected appropriately is more important than performance. Hopefully, folks behind compose keep that philosophy.
b

Ben Trengrove [G]

10/19/2023, 11:11 PM
We are hoping that with the changes being talked about there on the android show, having to mark something as stable will become the edge case we originally intended it to be.
❤️ 10
e

eygraber

10/20/2023, 1:32 AM
What are those changes (for those of us that didn't see it)?
c

curioustechizen

10/20/2023, 2:07 AM
There is one situation where I had to use the Stable annotation: when my state class had large lists. That turned into a habit of adding that annotation to every state class that I create.
b

Ben Trengrove [G]

10/20/2023, 2:32 AM
It's called "strong skipping mode". It's an experimental compiler option that makes composables with unstable parameters also able to be skipped
p

Pablichjenkov

10/20/2023, 2:40 AM
So only shallow equality will be checked and delegate the state mutation responsibility to the developer? - Sounds good tbh
b

Ben Trengrove [G]

10/20/2023, 2:40 AM
Unstable parameters will be compared for instance equality
thank you color 2
p

Pablichjenkov

10/20/2023, 2:41 AM
Makes sense, will make unstable parameters equality check super fast
👍 1
v

vide

10/20/2023, 4:44 AM
My team places a lot of care on manual skipping/stability optimization, but we don't deal with modern smartphones. We target ~10 year old embedded devices that barely run compose. There it has proven to be very important to squeeze all potential perf.
p

Pablichjenkov

10/20/2023, 4:55 AM
I agree 💯 with you Elias, but the fact that you mark it as Stable doesn't make it stable. As long as you use specific immutable libraries and proper patterns to update state it is fine. Then someone breaks those rules and things start not working.
v

vide

10/20/2023, 5:04 AM
Marking as stable definitely does make it stable 😅 There are a lot of edge cases where the compiler does not infer it automatically.
b

Ben Trengrove [G]

10/20/2023, 5:31 AM
Marking it stable makes the compiler consider it stable, it doesn't make it stable. Stable means you'll let compose runtime know about any mutations, in practice by using MutableState
☝️ 2
p

Pablichjenkov

10/20/2023, 5:41 AM
Check this Elias.
In regards to the new approach I am super positive about it. It should have always being like that,
instance equality
. Developers should know how to play with and propbably there is some edge cases, but it looks like most people are representing state with
sealed + data classes
and using
copy
to update the state, which makes the whole thing a great combination.
❤️ 2
z

Zoltan Demant

10/20/2023, 8:39 AM
I went pretty hard with
@Immutable
in an earlier project with performance problems (many complex screens, too). It did resolve the performance issues, but more notably: theres a clear difference in fluidity as compared to newer projects without the optimizations (despite the newer projects using the reworked Modifiers even; they werent available back then). Having the "optimized" version enabled by default would be awesome 👍🏽
👍 1
v

vide

10/20/2023, 9:58 AM
What I meant with "make it stable" is from the viewpoint of the compiler, because that's usually what matters
@Pablichjenkov @Ben Trengrove [G] I am well aware that the annotation doesn't change the class itself, but there are some cases where stability can't be automatically inferred by the compiler; for example when using non-compose aware classes from external sources. In this case you can have a practically stable class that you still need to manually annotate. Another use case is a class with mutable non-state values, where the mutable parts are only read in callbacks, not for producing UI state etc.
b

Ben Trengrove [G]

10/20/2023, 10:04 AM
Yes, no disagreement there
💯 1
p

Pablichjenkov

10/20/2023, 10:15 AM
Ah I see right, the inverse logic, if you 💯 sure no danger of mutability, not marking it as Stable is bad since you lose the opportunity to optimize. See your point now, good
1
e

eygraber

10/20/2023, 11:36 AM
@Ben Trengrove [G] is "strong skipping mode" written up anywhere, or is it just discussed in that video? In either case is there a link available for it?
a

ascii

10/20/2023, 12:55 PM
It's not finished yet, so there's no docs for it. Video mentions it'll come out next year:

https://youtu.be/_gL7XZy_XsY?t=3673

thank you color 1
c

Colton Idle

10/20/2023, 1:06 PM
I wonder if my use of snapshot state for everything that we want compose to recompose lessens the need for marking things as stable. @Ben Trengrove [G] glad to know the original intention for @Stable was for it to have to be seldom used.
a

ascii

10/20/2023, 1:08 PM
Many things are already interpreted as being
stable
by the compiler, as long as it can see that code. For example, a data class with only `val`s inside it doesn't need to be marked with any stability annotations.
I'm excited about strong skipping mode. It should've been this way from the beginning imo. But let's see what weird edge cases pop up later on.
3
😁 2
b

Ben Trengrove [G]

10/20/2023, 7:56 PM
No docs and all subject to change, very experimental. You can read the CL though if you want. https://android-review.googlesource.com/c/platform/frameworks/support/+/2671135
👍 3
a

ascii

11/08/2023, 5:14 AM
1.5.4 is out, with ^ this and https://r.android.com/c/2668595
👀 2
🔥 1
z

Zoltan Demant

11/08/2023, 5:42 AM
I dont have time to try this.. I dont have time to try this.. Oooh, shiny!
3
p

Pablichjenkov

11/08/2023, 5:43 AM
I LL be like
com.mypackage.**
😅 1
😁 1
z

Zoltan Demant

11/08/2023, 5:47 AM
Strong skipping works perfectly fine for me. Comparing with an earlier project where everything was `@Stable/@Immutable`; pretty much identical - without any of the hassle 😃 Huge thumbs up!
3
c

Colton Idle

11/08/2023, 8:28 AM
wowowowow!
v

vide

11/08/2023, 8:36 AM
I'll try it this week 👀
b

Ben Trengrove [G]

11/08/2023, 9:03 AM
Good to hear!
v

vide

11/08/2023, 3:02 PM
Tested enabling it, performance is marginally better in some areas that we haven't optimized manually and contain unmemoized lambdas and references to "un"stable external classes. No issues spotted so far.
👀 2
c

Colton Idle

11/15/2023, 9:42 PM
How do I enable it?
f

Francesc

11/15/2023, 9:54 PM
you can't for now, there is a bug in the compiler that prevents the new flag from being parsed
there is an open ticket for it
c

Colton Idle

11/15/2023, 9:57 PM
Really? A few people here said it worked!
f

Francesc

11/15/2023, 9:59 PM
are you talking about the stability path, where you define a set of classes or packages that the compiler will consider stable (like Kotlin collections)?
c

Colton Idle

11/15/2023, 10:07 PM
Oh sorry. I was talking about "Add a strong skipping mode option"
a

ascii

11/15/2023, 10:14 PM
strong skipping mode is this:
Copy code
plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true
Add it to your freeCompilerArgs or in the
compose
block if CMP.
I've turned it on, removed all the hacks to force-remember stuff like ViewModel callbacks, and it works. Haven't fully tested everything yet though.
b

Ben Trengrove [G]

11/15/2023, 10:22 PM
We just hid that hack in the compiler for you
c

Colton Idle

11/15/2023, 10:27 PM
So kotlinOptions { freeCompilerArgs += "pluginandroidx.compose.compiler.plugins.kotlinexperimentalStrongSkipping=true" } ?
👍 1
b

Ben Trengrove [G]

11/15/2023, 10:31 PM
Just keep in mind, we consider this very experimental. I wouldn't ship it to production right now
c

Colton Idle

11/15/2023, 10:32 PM
oh yeah. not shipping. just want to see what its all about.
Hm. "Source file or directory not found: pluginandroidx.compose.compiler.plugins.kotlinexperimentalStrongSkipping=true"
a

ascii

11/15/2023, 10:33 PM
You'll have to add "-P" before it
I think as a separate item, i.e. not in the "plugin:" string itself
c

Colton Idle

11/15/2023, 10:40 PM
alright. i have no idea what im doing. so ill keep trialing and erroring. thanks all. seems like im close
f

Francesc

11/15/2023, 10:41 PM
Copy code
freeCompilerArgs += listOf(
            "-P",
            "plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true"
        )
c

Colton Idle

11/16/2023, 12:20 PM
thanks! that seemed to work!
129 Views