Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • 11
    They have a strong concern for performance in part because immutability (sometimes) has a performance cost, and they want to minimize that performance cost as much as possible. Immutability, all by itself, only has performance benefits in the sense that it makes it easier to write multi-threaded code. Commented Dec 8, 2015 at 15:20
  • 10
    In my experience, performance is only a valid concern for two scenarios - one, when an action is performed 30+ times in one second, and two - when its effects increase with each execution (Windows XP once found a bug where Windows Update time took O(pow(n, 2)) for every update in its history.) Most other code is an immediate response to an event; a click, API request, or similar, and as long as execution time is constant, the cleanup of any number of objects hardly matters. Commented Dec 8, 2015 at 16:23
  • 4
    Also, consider that there exist efficient implementations of immutable data structures. Maybe these are not as efficient as mutable ones, but probably still more efficient than a naive implementation. See e.g. Purely Functional Data Structures by Chris Okasaki Commented Dec 8, 2015 at 16:32
  • 1
    @Katana314: 30+ times for me would still not be enough to justify worrying about performance. I ported a small CPU emulator I wrote to node.js and node executed the virtual CPU at around 20MHz (that's 20 million times per second). So I'd only worry about performance if I were doing something 1000+ times per second (even then, I wouldn't really worry until I do 1000000 operations per second because I know I can comfortably do more than 10 of them at once). Commented Dec 9, 2015 at 3:00
  • 2
    @RobertHarvey "Immutability, all by itself, only has performance benefits in the sense that it makes it easier to write multi-threaded code." That is not entirely true, immutability allows for very pervasive sharing with no real consequences. Which is very unsafe in a mutable environment. This gives you thinks like O(1) array slicing and O(log n) inserting into a binary tree while still being able to use the old one freely, and another example is tails which takes all the tails of a list tails [1, 2] = [[1, 2], [2], []] only takes O(n) time and space, but is O(n^2) in element count Commented Jan 2, 2017 at 22:22