15 ms·
Does the Bronze Garbage Collector Make Rust Easier to Use?
- ummonk 5y agoI think providing a garbage collector as training wheels as the authors are proposing would be counterproductive to helping beginners truly learn Rust.
- forgotmypw17 5y agoI was fortunate to see Michael present this recently, and found the presentation convincing. I may be a bit sheltered, but this was my first exposure to a study with so many volunteers completing involved coding tasks to assess language features. I find Figure 3 to be particularly convincing: http://shitmyself.com/image/figure3.png http://shitmyself.com/image/figure3.png
- adwn 5y ago> http://shitmyself.com/image/figure3.png http://shitmyself.com/image/figure3.png Why are you posting a link to a page which requires authentication?
- hayley-patton 5y agoIf you refuse to provide authentication, the page will tell you the authentication to provide. Not sure why this mechanism is in place.
- forgotmypw17 5y agoIt is basically a captcha to keep out crawler bots. I added an exception for images and then overwrote the config with a previous version... -_- Should be fixed now.
- forgotmypw17 5y agoSorry about that, I fixed the configuration and it shouldn't require auth anymore.
- akiselev 5y ago> To see whether Bronze could make Rust more usable, we conducted a randomized controlled trial with volunteers from a 633-person class, collecting data from 428 students in total. Well, this paper starts off with a bang. A quick search on github returns this repo [1] by mcoblenz who I assume is the first author Michael Coblenz. Unfortunately nothing but the readme has been updated in 10 months and I couldn't find a link to the latest source with a skim of the paper and bibliography. [1] https://github.com/mcoblenz/Bronze https://github.com/mcoblenz/Bronze
- rwmj 5y agoThis (unfortunately) is rather typical in academia - finish the paper and publish and move on to the next research topic. It would be a shame if the version of Bronze related to the paper forgot to be pushed, but I'm sure sending him a quick email will resolve that.
- redrobein 5y ago> ...indicated that ownership, borrowing, and lifetimes were primary causes of the challenges that... I thought this was kinda obvious. Reasoning about borrowing and lifetimes is hard if you've never done it before. But the real question is how long it takes users to learn it and what we can do to improve that. I wonder how close the plain rust users' times would get to bronze users over time as they keep doing similar tasks.
- CraigJPerry 5y ago>> I wonder how close the plain rust users' times would get to bronze users over time as they keep doing similar tasks. This is the real question for me. The rest is just implementation detail. Someone is (usually) paying for the code to be written. Are they getting more value for less spend over time? When you look at it through this lens though, there tend to be bigger overriding factors a rust compiler (or any other choice of language) can’t really help with - e.g. is the design & architecture of the code heading in the “ball of mud” direction. I.e. is change velocity going to reduce over time? With a garbage collector, yeah you most likely are getting more productivity out of a developer. You’ve delegated one of the hardest problems (when can i free this thing?) to the computer. Because of the way rust is designed, it doesn’t protect against memory leaks. It protects against use after free but not that i fail to release redundant memory. But unfortunately It’s not guaranteed that just adding a garbage collector will help with this. With a sufficiently good developer though, they should be able to move faster than if you make them Arc<> & lifetime everything themselves. It’s specifically the lifetime bit that consumes time / developer productivity. Using Arc<> isn’t hard or arduous in any way.
- jraph 5y agoIf you add a garbage collector to Rust, you neutralize one of its strength: the controlled lifetime of objects. You also make memory leaks easier. I'm convinced Rust is easier to write without the management of lifetimes in a short time span. However, what about long term maintenance, and application stability? Rust with a GC probably has its uses (compiled language with strong error checking), but one has to know what ship they are boarding. It also makes it quite closer to D, an "easier C++", compiled language with a GC. (I'm saying this as someone who tried Rust, and mostly uses GC'd languages) edit: thanks for the replies below. I hadn't though about this. I guess one should better read my message as "If you remove Rust's lifetime management, …"
- torginus 5y agoTbh, I'm not sure about this GC-purism. I've encountered tons of high-end C++ that's absolutely full of smart pointers, which is a form of GC. Rust has Rc<> and Arc<> as well. Having a a ref-counted GC instead of a tracing one doesn't seem like a step up in 'purity' to me.
- jeremyjh 5y agoRef-counting provides consistent performance - the costs are amortized smoothly over the operations. They aren't doing all this work for "purity".
- louthy 5y agoRef counting can also lead to memory leaks with circular references.
- deleted 5y ago[deleted]
- bjourne 5y agoPerformance of ref-counting is proportional to the size of the dead objects. Performance of tracing gc is proportional to the size of the alive objects. In other words, there are many real-world situations in which ref-counting pauses are much longer than tracing gc pauses.
- pshc 5y agoIs Bronze memory safe?
- kobebrookskC3 5y agounfortunately, it's unsound https://github.com/mcoblenz/Bronze/issues/2 https://github.com/mcoblenz/Bronze/issues/2
- codeflo 5y agoThat’s an evil problem to have. Let’s say you derive two references to a GC’d object (this can easily happen accidentally in a graph-like data structure) and pass them both as parameters to a function. I’ve looked at disassembled Rust code before. Given how aggressively the compiler optimizes based on the guarantees around & and &mut, I’d be surprised if this system compiles any non-toy programs correctly at all.
- deleted 5y ago[deleted]
- adwn 5y agoThis study, along with their GC library, is fundamentally flawed: The Bronze garbage collector doesn't just provide automatic memory management, it also allows shared mutable references! This undermines one of the most critical principles of Rust, one which is necessary for many of Rust's safety guarantees: There is never have more than one live mutable reference to the same memory location. As soon as you create two mutable references to the same memory location, you get undefined behavior, even if you don't dereference them. That's why the entire approach is flawed: They didn't study "Rust + GC", but effectively created a new language. See [1] for more details. Personally, as someone who uses Rust professionally, I believe optional GC would be a great addition to Rust! The compiler would provide support for GC, and the actual GC runtimes would be library-based, similar to how async/await is handled. However, this GC would merely replace Arc/Rc, not Mutex/RefCell/Cell. [1] https://users.rust-lang.org/t/bronze-gc-and-aliasing-problems/65679/9 https://users.rust-lang.org/t/bronze-gc-and-aliasing-problem...
- codeflo 5y agoI absolutely agree. There’s prior art in that direction. It’s more or less abandoned now, but Microsoft developed an extension to C++ that integrated the .NET runtime with it’s garbage collector called C++/CLI. The way it worked is that in addition to C++’s native pointers and references (Foo* and Foo&), you had a new kind of garbage collected reference, written Foo^. There were some annoying limitations that a GC built directly for this use case might have solved better, but mostly, this worked really well. And I think Rust would be a much better target language for such a system than C++ was. For example, one of the interesting problems was that the .NET GC is compacting — it will move objects around to improve cache locality and simplify the allocation algorithm. To interact with ordinary C++ code, you need native pointers into GC’d objects. But it was only safe to take such a pointer while you told the GC to temporarily “pin” the object in memory, otherwise, your pointer could be randomly invalidated. Forgetting that step was a very evil source of nondeterministic memory bugs. It’s not hard to see how the borrow checker would help there.
- pjmlp 5y agoIt isn't abandoned at all, it was one of the milestones for .NET Core 3.1 release and is currently up to date with C++17. Much easier than dealing with P/Invoke declarations or dealing with COM over RCW/CCW layer.
- veltas 5y agoThe short lifetime of most objects should be implicit from scope and obvious to the programmer. It's usually easier that way, and certain GC-based languages ended up adding special syntax to add that level of control for objects when the programmer wants fine-grained control over the destructor. And on the other hand, optional GC is something non-GC languages can end up adding too, like C++. Garbage collection is required (or convenient) for some problems, cleaning up objects that would be leaked by reference counting or weaker strategies. EDIT: deemphasised universality of this rule, not really important to my point anyway: that GC/non-GC memory management are more orthogonal than they appear from language feature discussions, in theory. I wasn't trying to imply literally "all" such languages add these features, I have just noticed a number of relevant cases.
- johnny22 5y agodidn't they remove GC from C++?
- veltas 5y agoI honestly don't know, maybe. There are libraries for it too though. https://hboehm.info/gc/ https://hboehm.info/gc/
- josephg 5y agoHuh? Which languages are you referring to? Javascript, Lua, Python and ruby are all GC based languages with (as far as I know) no special syntax for short lived objects. Does Go have syntax like that? The only GC language I can think of with special stack variables is C#. Are there others? Does Java do this now? And on the other side, I’ve still never seen a production C or C++ codebase which used a garbage collector. The closest I’ve seen is refcounting - but that’s a very different beast compared to what V8, .net, Go, etc do internally to garbage collect objects. The only languages I’ve seen which mix GC and non-GC code are D, Nim (I think), with an honourable mention for Obj-C / Swift’s ARC. But again, I’m not sure ARC belongs in the same category as the generational GCs we see in the JVM and others. With a few obscure exceptions, it seems to me that the gc/ non-gc line is still pretty firm for most programming languages.
- symmetricsaurus 5y ago> A key tradeoff is that Bronze does not guarantee thread safety Not having data races is one of the key benefits of using Rust, “fearless concurrency” and all that. So by throwing away a key guarantee of Rust (no aliasing mutable references), it can become easier for learners to program in. It becomes a bit of an apples and oranges situation at that point.
- pjmlp 5y agoData races across threads, Rust type system does nothing to prevent data races across processes.
- afdbcreid 5y agoIt's interesting to see if one can come with a solution based on custom `Send`/`Sync`-like traits. Of couse it will require nightly since auto traits are not stable.
- berkes 5y agoWhen can data races across processes happen? Are you talking about databases, services or IO and such?
- knuthsat 5y agoI guess the simplest example is shared memory between processes. Even Python has it: https://docs.python.org/3/library/multiprocessing.shared_memory.html https://docs.python.org/3/library/multiprocessing.shared_mem...
- tragomaskhalos 5y agoFrom https://crates.io/crates/bronze_gc https://crates.io/crates/bronze_gc : "The Bronze garbage collector for Rust. This version only includes the API for creating and using GC references; it does not actually collect anything. For experimental purposes only." (my emphasis) This seems to be at odds with the paper, which describes it as mark-sweep?
- Deukhoofd 5y agoFrom Github: > This implementation is experimental. The 'main' branch has a collector, but it only works in limited cases is not general enough to work with YOUR code. The 'API-only' branch has the collector disabled; be aware that you will eventually run out of memory. However, the present version is suitable for experimentation and prototyping.
- bruce343434 5y agoThat's sort of disappointing. Why do people insist on "releasing" and marketing before the product is even finished nowadays?
- mattgreenrocks 5y agoBecause we’ve all bought into the lie that branding is the most important part of product development.
- MobiusHorizons 5y agoI don't think bronze is actually intended to be used outside of the context of the study. My impression is that it exist purely to make it possible to to conduct a study to quantify the overhead of constructing code that can pass the borrow checker. It's possible the team behind this may have hoped to use the study as part of a grant proposal to get funding to build out a more robust GC for rust.
- booleandilemma 5y agoI’m saddened to think that because this industry has an obsession with making programming accessible to the lowest common denominator, expressive and innovative languages like Rust will fall by the wayside, and we’ll all be writing code in languages like Go and Python in the future because they’re “easy” and even high schoolers can learn them in a couple days. It reminds me of the longbow vs crossbow. One is a technology that anyone can learn to use easily, the other is one that takes longer to master, but is a more efficient weapon in the hands of a skilled soldier. The analogy isn’t perfect but the parallels are there. http://www.thebeckoning.com/medieval/crossbow/cross_l_v_c.html http://www.thebeckoning.com/medieval/crossbow/cross_l_v_c.ht...
- t_scytale 5y agoThere is absolutely no evidence to support this assertion. Instead there is plenty of evidence that currently there is a lot innovation in all niches of the programming ecosystem - from low level [Rust] to high level, and a lot of coder interest in all the options. Also talking about "lowest common denominator" comes across as somewhat snobby - many world-class coders use high-level languages when appropriate. It's a matter of choosing the right tool for the job, not dumbing down.
- deleted 5y ago[deleted]
- AnIdiotOnTheNet 5y ago> There is absolutely no evidence to support this assertion. Consider the popularity of Javascript and Electron for Desktop applications.
- Spivak 5y agoBecause it’s a first class development experience, cross-platform by default, V8 is really really fast, and toolkits that support “build your own toolkit” are non-existent outside the web. I don’t want to make a “Windows app”, “A Mac app”, or a “QT app”. I want a rectangle and a high-level enough interface to build my own widgets. People who are single mode users obviously hate that every app looks and behaves different but most people are multi-mode and don’t care. JS is only easy at the most superficial level and gets to be a mess once you go beyond small apps.
- ModernMech 5y ago> [the borrow checker] makes Rust relatively hard to learn and use. I would say the borrow checker makes rust harder to learn, but it does not make it harder to use once you actually grok it. When that time comes, the borrow checker fades into the background. When I got to that point with Rust, it became much easier to use than other languages for me (others I use being C++ and C).
- elzbardico 5y agoWhy do we need to make everything easier to beginners? Are the beginners supposed to stay as beginners forever?
- keymone 5y agoValid point, but if a good system deters beginners by being too complex and hard to use - adoption will suffer. We want good systems to have high adoption.
- nestorD 5y agoManish Goregaokar has a wonderful blog post on garbage collectors in Rust, the current implementations, the trade-offs and where they might be worthwhile: https://manishearth.github.io/blog/2021/04/05/a-tour-of-safe-tracing-gc-designs-in-rust/ https://manishearth.github.io/blog/2021/04/05/a-tour-of-safe...
- moltonel3x 5y agoThere are a lot of Rust GC approaches here, makes me wonder why the study author didn't use one (or more) of the existing sound GCs. Remove a glaring flaw of the study, and spend less time writing throw-away code.
- ashtonkem 5y agoWhy would you want to add garbage collection to rust? Doesn't that undermine one of its key value propositions?
- staticassertion 5y agoRust is already extremely easy to use.
- alexchamberlain 5y agoIs a study based on students the best way to measure the productivity of a language? It would be interesting to see what Rust experts code do with and without, for example.
- dathinab 5y agoThe thing is rusts owner ship system doesn't "just" provide memory handling, it provides reliable hard to get wrong resource handling for all kinds of resources. To some degree for me this is *more* important then the memory handling aspects. For example the whole "collection modified while iterating over it" situation can easily become a nightmare, especially for new programmers. It also does happen in non multi-threaded code all the time (if there are some "cross-cutting" concerns). In many GCed languages/libraries running into this situation is "safe" but unspecified. Worse if it happens to work in some situations (it often does) it's not rare for programmers to rely on this behaviour. That is until it gets subtitle broken due to other code changing, or the library changing. In rust this problem is not a thing, the borrow checker prevents you from accidentally running into it by accident. If you need it there are ways to still get it, but now with well define characteristics. So while this is initially more work, it is much much less bug prone and easier to maintain. And that's just one example. The borrow checker might be more initial work, but it often makes you write better, less buggy, easier to maintain code independent of memory management. That is if you don't get over-obsessed with never cloning, never using Rc/Arc etc. then you are in for pain. Being over-obsessed with only using borrows is a form of premature optimizations. (As a side note even with clones/Rc/Arc the borrow checker still helps you as it's not the same as replacing it with a GC).