Experiment with smaller Zustand state updates
joebobmiles opened this issue · comments
Joseph R Miles commented
The middleware asks Zustand to replace the state with a new state object. This feels inefficient, but I need to test to see which is faster: full replacement or using partial updates.
Joseph R Miles commented
Had a peek at the Zustand source code and learned that, in fact, the larger updates are more efficient. This is due to the replace
parameter bypassing an Object.assign()
call when set to true
. This skips straight to re-assigning the internal state to the new state.
The difference in performance is a constant time operation (reassignment) versus a linear time operation (Object.assign()
).