3 ms·
One interesting thing about having entirely immutable data structures is that you can allocate a temporary heap, and flip the GC around. Copy off just the resul
by reitzensteinm 13y ago
One interesting thing about having entirely immutable data structures is that you can allocate a temporary heap, and flip the GC around. Copy off just the result and junk the rest without looking at it. All without blocking the main thread.
In certain circumstances - for instance a web framework creating a heap for each request - this will make GC dramatically cheaper. Though of course your cache locality will be poor.
- cynicalkane 13y agoThis is a common practice in GC. For example, the JVM already does this by default, and you don't need to give it immutable data.
- reitzensteinm 13y agoBut immutability makes it conceptually a hell of lot cleaner, and feasible to do even if you're investing orders of magnitude less in your GC than went into the JVM. Which is important if Clojure gets ported to bare metal runtimes, as the parent was suggesting.
- lucian1900 13y agoThat technique (commonly called semispace GC) works for mutable data as well, as long as you have a pointer indirection (so you can move), it's just less efficient than most others. It would be interesting to see whether the balance would shift significantly with immutable objects.