Persistent and Transient Data Structures
Immutable data structures are also sometimes referred to as persistent data structures, since its values persist for its lifetime. Immutable.js provides the option for transient data structures, which is a mutable version of a persistent data structure during a transformation stage and returning a new immutable version upon completion. This is one approach to solving the performance issues we encountered earlier. Let's revisit the immutable case outlined in the performance example, but using a transient data structure this time:
As we can see in this performance test, the transient list builder was still a lot slower than the fully mutable version, but much faster than the fully immutable version. Also, if you pass the mutable array to Immutable.List
or Immutable.fromJS
, you'll find the transient version closes the performance gap. The test also shows how slow Object.freeze
can be compared to the other 3.
Last updated
Was this helpful?