The benefits of purely functional data structures
Purely functional data structures have the following advantages:
Persistence: old versions can be reused safe in the knowledge that they cannot have been changed.
Sharing: many versions of a data structure can be kept simultaneously with relatively modest memory requirements.
Thread safety: any mutation is hidden inside lazy thunks (if any) and, therefore, thread safety is handled by the language implementation.
Simplicity: not having to keep track of state changes often makes purely functional data structures simpler to use, particularly in the context of concurrency.
Incrementality: purely functional data structures are composed of many tiny parts, making them ideal for incremental garbage collection, leading to lower latencies.
Purely functional data structures also have the potential to be beneficial in the context of parallel programming for multicores. However, efficient multicore parallelism requires predictable locality in order to leverage caches and avoid getting bottlenecked on access to shared caches and main memory and purely functional data structures have, at best, unknown characteristics in this regard. Consequently, many programs that use purely functional data structures do not scale well when parallelized on a multicore because they spend all of their time in cache misses, contending for shared memory pathways.
Comments
Post a Comment