elizarov
03/05/2017, 7:22 AMgroostav
03/06/2017, 7:11 PMArrayList
with (Immutable) List.plus
. I want a proper Immutable collection that maximizes sharing. this is one of my favourite talks on the subject: https://www.infoq.com/presentations/Functional-Data-Structures-in-Scalaelizarov
03/06/2017, 7:46 PMArrayList
with List.plus
(why would anyone do this in performance-critical code?). I'm talking about their comparison with mutable data structures that you actually mutate (instead of rebuilding into new ones). The important datum to keep in mind is that most collection-manipulating code in real apps is read-only. You rarely modify maps and lists, but you query them a lot. Take Kotlin compiler, for example. It would build its a scope once and then query it many time while compiling the corresponding block of code.
The worst part of the performance of persistent collections is that their query operations asymptotically (big O) and practically (even at small N) are much slower. The fact that you can efficiently combine them does not buy a lot in practice. Most practical algorithms (from data analysis to code compilation) become asymptotically slower when you express them in terms on persistent data structures. The cases where persistent data structure is a right choice from performance standpoint are extremely rare and niche. However, from thread-safety standpoint the decision to use persistent data structure is often a good one, because you gain simplicity and ease of reasoning about your concurrent code, despite loss of performance that is not important in many areas.groostav
03/06/2017, 11:28 PMjava.util.arraylist
.
Your point is of course perfectly valid on persistant domain models, because implementing sharing on those is a very difficult committment. But for collections, I feel like scala and clojure both have stunningly effective persistent implementations.groostav
03/06/2017, 11:28 PMwhy would anyone do this in performance critical codebecause IIRC the current implementation of
listOf("one", "two") + "three"
would do this by default.