Skip to main content
Question Protected by gnat
Tweeted twitter.com/StackProgrammer/status/674285018311753728
edited tags
Link
gnat
  • 20.5k
  • 29
  • 117
  • 309
Source Link
callum
  • 10.5k
  • 9
  • 32
  • 35

Does immutability hurt performance in JavaScript?

There seems to be a recent trend in JavaScript towards treating data structures as immutable. For example, if you need to change a single property of an object, better to just create a whole new object with the new property, and just copy over all the other properties from the old object, and let the old object be garbage collected. (That's my understanding anyway.)

My initial reaction is, that sounds like it would be bad for performance.

But then libraries like Immutable.js and Redux.js are written by smarter people than me, and seem to have a strong concern for performance, so it makes me wonder if my understanding of garbage (and its performance impact) is wrong.

Are there performance benefits to immutability I'm missing, and do they outweigh the downsides of creating so much garbage?