-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The case for Immutability #6
Comments
@rjmk can you please explain why immutability in JS leads to a performance improvement even as Memory Consumption _increases_? |
Immutability using data structures such as those provided by Mori.js create trie structures which share common content between old and new versions of the data, so memory consumption may not be as bad as you think. Immutability can also give you huge performance optimization opportunities, especially where it's necessary to compare changes against two different deeply nested trees (for example, the React virtual DOM vs actual DOM diff). Using immutable data structures, the diff check is literally an identity check -- about as fast as a comparison gets. Using mutable trees, you have to traverse the whole tree and compare each node just to find out whether or not anything has changed. There are lots of other advantages to immutability, including enabling great features like unlimited undo/redo, history shuttles, and even time-travel debugging. Immutability also adds a lot of guarantees that make understanding and debugging software easier, and completely eliminates entire classes of code and potential bugs. |
@NataliaLKB You were telling me about your recent learnings on mutable and immutable objects on Saturday! Was just wondering if you have anything to add on what you've learnt 😉 |
I agree with everything @ericelliott has said so far. Especially the last line.
Even if memory consumption increases, it is entirely worth it for all the other benefits |
Agree with @ericelliott and @NataliaLKB. Especially Natalia's last comment.
|
http://www.youhavetolearncomputers.com/blog/2015/9/15/a-conceptual-overview-of-redux-or-how-i-fell-in-love-with-a-javascript-state-container
http://programmers.stackexchange.com/questions/151733/if-immutable-objects-are-good-why-do-people-keep-creating-mutable-objects
The text was updated successfully, but these errors were encountered: