r/Clojure • • Jun 11 '19

GitHub - timothypratley/rustly: A Clojure to Rust transpiler

https://github.com/timothypratley/rustly
73 Upvotes

15 comments sorted by

View all comments

6

u/vvvvalvalval Jun 11 '19

What's the strategy for memory management?

3

u/dustingetz Jun 12 '19

I always thought a prerequisite to immutable collections was a strong gc but i wonder how these work https://github.com/bodil/im-rs

10

u/halgari Jun 12 '19

They work just fine, but the problem comes with CAS contention. A atomic increment can take about 300 cycles on modern hardware and it flushes that cache line from some caches. With a RC system you’d end up doing a inc/dec on every read to every level of the persistent tree while you’re reading it. Rust supports this via the Arc reference type, but we’re still talking about a thousand cycles wasted just on bookkeeping while reading from a hashmap.

There are optimizations for all of this, but it’s true, the cost of persistent structures is much higher in a non GC context