Reputation: 330
Data normalization is usually recommended with Redux in order to avoid unnecessary re-rendering of the components.
For instance, if you have blog posts and comments, all the nested comments need to be stored in a single flat array at the root of the store. It seems to me that while solving the perf issue with re-rendering, it introduces another perf issue when adding or updating comments since we need to copy the whole array in that case (in order to satisfy immutability requirement). Since we can easily have tens of thousands comments, it will become a performance problem pretty quickly. Am I missing something or this is actually the case?
Upvotes: 1
Views: 120
Reputation: 42228
When you copy the array
of comments you are creating what's called a "shallow copy". The array
itself is totally new, but each comment object
inside the array is not a new object
- it is a reference to the existing object
. Only the one comment which you are editing will have a new comment object
. Because of this, the performance impact of copying the array
is minimal.
Upvotes: 1