In particular, if you need to apply any transformation to your model before displaying it in a view, it's not going to be a fast pointer check - you need to do dirty checks on all the elements just like you would with mutable data structures.
In particular, if you need to apply any transformation to your model before displaying it in a view, it's not going to be a fast pointer check - you need to do dirty checks on all the elements just like you would with mutable data structures.
immutableEq(a1, a2) {
return (a1 === a2) || all(mapPair(a1, a2, immutableEq))
}
Now if you update the value of a single element in the array a2, you would not have to check all the elements in depth (only their references): a1 = Immutable.List(el1, el2, el3, el4, el5)
a2 = a1.set(2, Immutable.Map({hello: "world"}));
immutableEq(a1, a2) // all but el3 compared by reference equalityIf you have a pipeline then it's going to result in everything downstream re-running, unless you compare the output of the map() transformation to the previous value, like some build systems do.
This conforms with my understanding as to why Clojure is slowish. That being said, I don't really understand why Haskell is seen as fast and Clojure is seen as slow (I am ignoring JVM warm-up times here).
Do they use fundamentally different algorithms under the covers?
Clojure's immutable datastructures are ~25% slower than standard java, but also eliminate entire classes of bugs.
I'm not familiar with Haskell's immutable data structures, but I'd be very surprised if there's an optimization that hasn't been adopted by Clojure. Rich Hickey put a lot of work into optimizing them.