Blog post: Rust vs Julia in scientific computing

Apologies if someone has already mentioned this, but I wanted to address one small technical point about GC vs manually-managed memory. First, let us all agree that allocation-free will nearly always be better (which it sounds like both Julia and Rust are sometimes capable of), and restrict ourselves to the case where any decent solution to a problem requires some form of dynamic memory allocation. In such cases, is it really clear that you get better performance from manual management? I don’t know if you’ve looked at the implementation of C/C++'s free, but it’s not exactly trivial. There are papers that have addressed this issue and often they seem to find that the two are pretty competitive:

https://www.researchgate.net/publication/340314454_Garbage_Collection_vs_Manual_Memory_Management_Performance_and_Memory_Consumption_Issues

A possibly-tolerable analogy is if I’m cooking a meal, does the strategy I use to load dirty dishes in the dishwasher matter? If I load them one-by-one (aka, like manual memory management), I never have a big pile of dishes next to the sink, but I pay a small overhead to opening and closing the dishwasher each time. Conversely, if I let them pile up (aka, like GC), I get some economies of scale from “batch-loading”; but if I let the piles grow too large, I end up wasting a lot of time managing the risk of the entire stack tipping over.

In my view, given that they are fairly equivalent in performance, I’d choose GC for any system that isn’t very memory-restricted (e.g., excluding embedded systems which profit a lot from a manually-managed memory scheme).

In Julia, because type-instability is often associated with GC usage, there’s a natural tendency to think “GC = bad performance.” But this is more a statement about “bad code” than a real comparison between the two memory management strategies.

34 Likes