Skip to content

Commit

Permalink
Add comment on deep cloning and re-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Jan 12, 2018
1 parent 3ccc27c commit 4c9cbd1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/faq/Performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ If you actually are concerned about reducer performance, you can use a utility s

Immutably updating state generally means making shallow copies, not deep copies. Shallow copies are much faster than deep copies, because fewer objects and fields have to be copied, and it effectively comes down to moving some pointers around.

In addition, deep cloning state creates new references for every field. Since the React-Redux `connect` function relies on reference comparisons to determine if data has changed, this means that UI components will be forced to re-render unnecessarily even though the other data hasn't meaningfully changed.

However, you *do* need to create a copied and updated object for each level of nesting that is affected. Although that shouldn't be particularly expensive, it's another good reason why you should keep your state normalized and shallow if possible.

> Common Redux misconception: you need to deeply clone the state. Reality: if something inside doesn't change, keep its reference the same!
Expand Down Expand Up @@ -158,4 +160,4 @@ Third, only cache a single copy of a record. This is especially important when r
**Discussions**
- [Stack Overflow: How to choose the Redux state shape for an app with list/detail views and pagination?](https://stackoverflow.com/questions/33940015/how-to-choose-the-redux-state-shape-for-an-app-with-list-detail-views-and-pagina)
- [Twitter: ...concerns over having "too much data in the state tree"...](https://twitter.com/acemarke/status/804071531844423683)
- [Advanced Redux entity normalization](https://medium.com/@dcousineau/advanced-redux-entity-normalization-f5f1fe2aefc5)
- [Advanced Redux entity normalization](https://medium.com/@dcousineau/advanced-redux-entity-normalization-f5f1fe2aefc5)

0 comments on commit 4c9cbd1

Please sign in to comment.