Would this be a proper usecase for Snapshot? I dont want to trigger UI Update on every iteration of the loop
So, with this, I guess it’ll only trigger update after the
apply
is called. What do you guys think?
a
Alex Vanyo
11/30/2022, 7:03 PM
The behavior here depends on the thread you’re running that code on. If you’re running on the main thread, the whole loop will run before any UI updates are triggered, so the
Snapshot.withMutableSnapshot
is probably not needed.
If you’re on a background thread instead, that story changes a bit and
More specifically, if you’re running this on a background thread, there’s a race condition where this can trigger multiple UI updates iff vsync triggers a recomposition while your loop is running. That’s probably unlikely to happen often, but certainly possible.
Recomposition doesn’t get invalidated on every state change, and it doesn’t run more than once a frame no matter how many times it’s invalidated for that frame.
If you can guarantee this is running on the UI thread, the extra snapshot is not worth the overhead.
t
thelumiereguy
12/01/2022, 2:06 AM
Yep. This will be run on the main thread. So, I don’t think this will be needed.
Thank you very much for the information!!