5 ms·
If you fit a gc on top of rust, the result is going to be less efficient than when using a modern gc'd language to begin with. So I'm curious what drove them to
by amelius 2y ago
If you fit a gc on top of rust, the result is going to be less efficient than when using a modern gc'd language to begin with. So I'm curious what drove them to this.
- the_mitsuhiko 2y agoThe answer to your question is in the linked post.
- Aurornis 2y agoThis is a garbage collector written in Rust, not "on top of" Rust. This isn't equivalent to adding garbage collection to the entire language. It's a garbage collected pointer type that can be employed for specific use cases. The article and the repo explain why they developed it: Implementing VMs for garbage collected languages in Rust.
- amelius 2y ago> It's a garbage collected pointer type that can be employed for specific use cases. You mean use cases where performance does not matter?
- twiss 2y agoDo you think Lua (for example, or any other GC'd language) has valid use cases? If so, it needs an implementation. This blog post shows (part of) one way to do that.
- remexre 2y agoUse-cases like "implementing a garbage-collected language."
- amelius 2y agoHigh performance garbage collectors are typically written in assembly because of the intricacies of the cache hierarchy.
- remexre 2y agoWhich one(s) are you thinking of? The JVM's appear to be in C++, GHC's and SBCL's are in C, Go's is in Go, and I'm not familiar with other high-performance garbage-collected platforms.
- hayley-patton 2y agoCitation very much needed, please; assembly wouldn't give you more control over caches than any language with a prefetch intrinsic.
- adgjlsfhk1 2y agoit also helps to have instructions that perform non-temporal reads and writes
- tinco 2y agoI spent some time porting the Go garbage collector to Rust, it was most definitely not written in assembly, and was (at the time) known as one of the most high performance garbage collectors for its particular use case. And even if there was some assembly at some deep level I hadn't got to yet, you can easily embed assembly in Rust so it wouldn't be an issue. Also, what sort of problem would there be with cache hierarchies that assembly would be a good solution for? Do you mean just guaranteeing the collection loop runs in L1 cache?
- 2y ago
- vlovich123 2y agoOut of curiosity, what language do you think the Java, JavaScript, and Python VMs and garbage collectors are written in? If you can understand why the VM is typically written in a systems programming language that doesn't itself have a VM or garbage collector, then you can start to think about why this is useful regardless of whether performance matters or not (& Java and C# are generally considered fairly high performance languages and VM implementations with efficient garbage collectors - the downsides may not matter to your problem domain).
- neonsunset 2y agoTo expand on GPs point, I believe it implies that implementing a GC type for the Rust itself within its constraints (and even LLVM is not perfect, if we skip to LLVM-IR) is bound to be worse than in a language with bespoke precise+tracing+moving garbage collector which always requires deep compiler integration for "VM" to have exact information of where gcrefs are located at every safepoint (including registers!), be able to collect objects as soon as they are no longer referenced and not when they go out of scope later, determine whether write (or, worse, read) barriers are required or can be omitted and have the ability to suspend the execution to update the object references upon moving them to a different generation/heap/etc. All GC implementations in Rust that I've seen so far relied on much more heavy handed techniques like having GC<T> to be a double indirection, pushing references to threadlocal queue, have GC pointers to be fat to pass around metadata inline, etc. They have been closer to modified RC with corresponding cost.
- binary132 2y agoI read it as something like “GC plus safety checks is costlier than just GC”
- adrian17 2y ago> All GC implementations in Rust that I've seen so far relied on much more heavy handed techniques like having GC<T> to be a double indirection, pushing references to threadlocal queue, have GC pointers to be fat to pass around metadata inline, etc. They have been closer to modified RC with corresponding cost. For reference, the gc-arena crate discussed in the blog post has no double indirection and no fat pointers (except for DSTs). Passing and reading the references is free, while assigning references to GC objects requires a write barrier, like in C#. The library is single-threaded, so there's no thread local state (and no global state). But you're right that since the library is not _that_ invasive or integrated with the language runtime / allocators, you don't get things like cheap allocations, barrier omitting or generations. And most notably, without stack scanning you can't do collection while in a GC-aware scope - in particular, you can't automatically run GC if you run out of memory during an allocation. Piccolo (Lua VM) solves this by being stackless and repeatedly jumping out of the GC scope, while Ruffle (Flash/AS2/AS3 VM) bites the bullet and only runs collection between frames and hopes that it'll never hit OOM within a single frame.