Performance issue with snapshots on a very large state. #782
Unanswered
guillaumebrunerie
asked this question in
Bug report
Replies: 1 comment 1 reply
-
If the state is subscribed, we know what property is charged. Otherwise, it's not tracked and we need to recursively check if anything is charged. I think such cases are covered by tests, so feel free to play with it. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use Valtio, but I am having some performance issues with the
snapshot
function, so I would like to understand better how it works with nested objects. Consider the following code:What I would expect is that the second snapshot should shallow clone
object
andobject.b
, but leaveobject.a
alone.But when stepping through it in the debugger, the
ensureVersion
function seems to still go through all the 10000 elements of theobject.a
array.Is that really necessary? I thought that given that nothing changed inside
object.a
, there should be no need to go through it at all, not even to update any version numbers (as the version number ofobject.a
should suffice). But I might be misunderstanding how it works.I’m experimenting with replacing Redux with Valtio in a complicated app with a very large state and very frequent changes, I replaced
useSelector
by a custom hook that callsuseSnapshot
instead, but every snapshot seems to take at least several hundreds milliseconds to make, and I have a lot ofuseSelector
calls, so the app doesn’t even start at all, the page is just frozen, and every time I pause the debugger to see what is going on, it is always inside a long call stack ofensureVersion
calls.Beta Was this translation helpful? Give feedback.
All reactions