Heard my friend comparing two implementations of persistent data structure last night. I remembered an interesting difference. In Clojure, when
dissoc is applied on a sub tree, Clojure will try to find out if we can reduce the depth of the tree. If it’s possible to reduce the depth, then just change the structure. While in Scala, it’s not detected and the depth would remain.
Then the result was interesting. In Clojure, a same piece of data always has same tree structure, while in Scala, there are some chances we got a tree with different structures, since it might be caused by creating deep trees but left there. Thus Clojure can be faster in some edge cases when we are comparing two pieces of data which are supposed to be equal, because the structure is the same.
identical? in Clojure.
But we use
= frequently. And people seem to prefer using
identical? in Clojure. So I want to know if I can trust
= that it’s faster enough and I don’t need to use
identical? when performance is cared about?