are these skipped recompositions a performance iss...
# compose-android
n
are these skipped recompositions a performance issue?
s
Nope, skipped recompositions means that your content didn't to be recomposed and was using the previous values it had.
d
Why would they be a performance issue?
They are the very thing that make up good performance in Compose Lol
n
Explaining the context a little bit... I'm implementing a server-driven UI. So, basically, my UI is observing a tree. Then, if some element of the tree has changed in the server, I receive the new tree and pass it to the composable function.
d
Got it!
SDUI is fun stuff
1
I did some of that awhile back.
s
If anything, the non skipped ones would be a performance issue, not the skipped ones.
s
As someone who did some of tree diffing, consider calculating list of changes on server and only updating subtrees that changed. Clients are usually less performant/efficient at processing those updates and Compose still has to go through equality checks for nodes top-to-bottom.
👍 2
n
@shikasd you touched the exact point that I need to know. In fact, the server is actually giving me the exact node that has changed... But how can I refresh a specific item in the compose view tree? 🤔
d
How are you structuring the data you feed into compose?
n
Imagine that I'm passing a tree (a
Node
object which can contain children). Something like:
Copy code
ServerUi(node=root)
inside of the
ServerUi
I'm checking...
Copy code
when (node.tag) {
"text" -> // call a Text composable
"column" -> // call a Column
"button" -> // call a Button
// etc..
}
d
So you have no way to find the backing node by it’s ID and ask it to update it’s state?
n
Yes, I have.
d
Is the state observable by the composable rendering it?
If so, then that composable should be able to update itself in place, no?
n
Yes. The root node is observable. But when I update a child node (at some level of the tree) and I pass the updated tree to the
ServerUi
composable, what happens is that skip counter of the other elements increase
d
If only the root node is observable then you have to rebuild the entire UI again when it changes. I am no expert at this, but I might approach it with something like this:
Build your tree out of these things (or something like it) and control it from a ViewModel.
You could index the nodes in a Map and find the node by ID and tell it to update it’s properties. Or you could just do a traversal of the tree until you find the one you want and tell it to update.
s
@nglauber consider wrapping each node with a mutable state and update it in place :)
👍 1
👌 1
n
Thanks @shikasd and @dewildte. I tried but didn't work... Maybe I missed something
Update: it worked. Thanks, guys 😉
🚀 1
🎉 1
d
What did you do and why was it not working before?
n
It was a few mistakes in my logic... 🙂 • In my data structure, the text of a
Text
server element was considered a leaf of my tree. Then I was trying to update the state using the ID of the leaf, where I should use the ID of the parent. • Another issue was that I'm using a
data class
in the state, and a
var
field was not being considered in the
equals
function, so Compose was not considering the state change and the recomposition was not working... There were a few more things... But to summarize, it was all my mistake 😄