|
|
|
|
|
by MillenialMan
1698 days ago
|
|
You're right - I missed that, the author does mention arrays having better access characteristics, although he doesn't really explain why HAMTs specifically are slow. How does Clojure's HAMT avoid fragmenting over time? > Clojure standard library works on arrays just fine, as demonstrated in the article. Right, but then you don't have immutability - so you lose all the guarantees that you originally had with immutable-by-default. |
|
Hello, author here :)
HAMTs are certainly slower, for "churning" operations, i.e., lots of updates, which is where Clojure exposes the transient API, which gives you limited localized mutability (some terms and conditions may apply)
Where iteration is concerned, they standard library implementation is pretty good. It relies on chunks of 64 element arrays which store the keys and values contiguously. Thus, APIs which expose direct iteration, Iterator and IReduce(Init) operate on these chunks one at a time. It isn't as fast as primitive arrays, but it's pretty fast.