Skip to content
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

Open
nelsonic opened this issue Dec 14, 2015 · 5 comments
Open

The case for Immutability #6

nelsonic opened this issue Dec 14, 2015 · 5 comments

Comments

@nelsonic
Copy link
Member

nelsonic commented Dec 14, 2015

@nelsonic
Copy link
Member Author

@rjmk can you please explain why immutability in JS leads to a performance improvement even as Memory Consumption _increases_?

@ericelliott
Copy link

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.

@iteles
Copy link
Member

iteles commented Dec 15, 2015

@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 😉

@NataliaLKB
Copy link
Member

I agree with everything @ericelliott has said so far. Especially the last line.

Immutability also adds a lot of guarantees that make understanding and debugging software easier, and completely eliminates entire classes of code and potential bugs.

Even if memory consumption increases, it is entirely worth it for all the other benefits

@rjmk
Copy link

rjmk commented Dec 17, 2015

Agree with @ericelliott and @NataliaLKB. Especially Natalia's last comment.

Especially the last line.

Immutability also adds a lot of guarantees that make understanding and debugging software easier, and completely eliminates entire classes of code and potential bugs.

Even if memory consumption increases, it is entirely worth it for all the other benefits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants