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

Zoltan Demant

02/07/2022, 7:37 AM
If I know that a variable is `@Immutable`; but I cant mark it directly myself - is there another way to acheive the same thing/optimizations? 🧵👀
Im seeing some pretty serious performance improvements by using
@Immutable
due to the state changing quite frequently, and a lot of composables depending on that state. Unfortunately its not possible to mark a function variable
@Immutable/Stable
(and I can understand why). Ive tried creating a wrapper class which is
@Immutable
, but my composable functions eventually accept the wrapped value and therefore lose out on the fact that its immutable. Im not able to refactor my code to accept the wrapper class (without a major headache, there are 758 cases like this). Due to the sheer amount of classes that would be marked immutable, Id very much prefer to not mark each individual one (or subclass a marked interface). They are always immutable.
Copy code
@Immutable
interface Screen
Is there another way?
So, I wrote a feature request for this to be included in the roadmap. If youve experienced anything similar, feel free to leave a comment in the request. Still on the lookout for alternative approaches in the meantime!