15 ms·
Yeah, immutable collections have to use structure-sharing to be implemented efficiently and this frequently results in common operations allocating lots of smal
by fiddlerwoaroof 2y ago
Yeah, immutable collections have to use structure-sharing to be implemented efficiently and this frequently results in common operations allocating lots of small objects rather than updating some object in-place.
- zozbot234 2y agoYou can use a borrow checker to replace immutable objects with update-in-place ("ephemeral") ones where feasible.
- fiddlerwoaroof 2y agoAnd, escape analysis and "dynamic extent" hints can have similar effects by stack-allocating intermediate values. Also, you can design your transformations to compose before handing off to a result builder, which is how modern Clojure reduces this problem.