Live data from Hacker News

Garbage collection for Rust: The finalizer frontier

soft-dev.org

111–120 of 184 posts

Re: Garbage collection for Rust: The finalizer frontier

#111
post #71

Earlier quoted context omitted.

I'm trying and failing to imagine a situation where 30ms startup time would be a problem. Maybe some kind of network service that needs to execute a separate process on every request?

30ms is the absolute best case. Throw some spring in there and you're very quickly at 10s. rub some spring-soap and it's near enough to 60s

And imagine if you start adding sleep calls! Those could take minutes to hours, or even days!

Re: Garbage collection for Rust: The finalizer frontier

#112
post #40

Earlier quoted context omitted.

it depends completely on what you put in "modern features"

Pattern matching, usable abstractions, non null types, tagged unions or w/e enums are, build tools etc

Scala but it's on JVM (also is https://scala-native.org without JVM but that not really has big user base)

Re: Garbage collection for Rust: The finalizer frontier

#113
post #71

Earlier quoted context omitted.

Testing on my machine, Hello World in java (openjdk 21) takes about 30ms. In contrast, "time" reports that rust takes 1ms, which is the limit of it's precision. Python does Hello World in just 8ms, despite not having a separate AOT compilation step. The general guidance I've seen for interaction is that things start to feel laggy at 100ms; so 30ms isn't a dealbreaker, but throwing a third of your time budget at the b…

I'm trying and failing to imagine a situation where 30ms startup time would be a problem. Maybe some kind of network service that needs to execute a separate process on every request?

30ms is pretty close to noticeable for anything that responds to user input. 30ms startup + 20-70ms processing would probably bump you into the noticeable latency range.

Re: Garbage collection for Rust: The finalizer frontier

#114
Memory safety would be a good idea indeed. Just to get rid of the unsafeties in the stdlib and elsewhere. With this would also go type-safety, because there will be no more unsafe hacks. Concurrency safety would another hill to die on, as they choose not to approach this goal with their blocking IO and locks all over.

Re: Garbage collection for Rust: The finalizer frontier

#115
post #44

> Having acknowledged that pointers can be 'disguised' as integers, it is then inevitable that Alloy must be a conservative GC C# / dotnet don't have this issue. The few times I've needed a raw pointer to an object, first I had to pin it, and then I had to make sure that I kept a live reference to the object while native code had its pointer. This is "easier done than said" because most of the time it's passing strin…

Even their so-called conservative assumption is also insufficient. > if a machine word's integer value, when considered as a pointer, falls within a GCed block of memory, then that block itself is considered reachable (and is transitively scanned). Since a conservative GC cannot know if a word is really a pointer, or is a random sequence of bits that happens to be the same as a valid pointer, this over-approximates t…

What you're describing is not just a problem with GC, but pointers in general. Optimizers would choke on exactly the same scheme.

What compiler writers realized is that pointers are actually not integers, even though we optimize them down to be integers. There's extra information in them we're forgetting to materialize in code, so-called "pointer provenance", that optimizers are implicitly using when they make certain obvious pointer optimizations. This would include the original block of memory or local variable you got the pointer from as well as the size of that data.

For normal pointer operations, including casting them to integers, this has no bearing on the meaning of the program. Pointers can lower to integers. But that doesn't mean constructing a new pointer from an integer alone is a sound operation. That is to say, in your example, recovering the integer portion of y and casting it to a pointer shouldn't be allowed.

There are two ways in which the casting of integers to pointers can be made a sound operation. The first would be to have the programmer provide a suitably valid pointer with the same or greater provenance as the one that provided the address. The other, which C/C++ went with for legacy reasons, is to say that pointers that are cast to integers become 'exposed' in such a way that casting the same integer back to a pointer successfully recovers the provenance.

If you're wondering, Rust supports both methods of sound int-to-pointer casts. The former is uninteresting for your example[0], but the latter would work. The way that 'exposed provenance' would lower to a GC system would be to have the GC keep a list of permanently rooted objects that have had their pointers cast to integers, and thus can never be collected by the system. Obviously, making pointer-to-integer casts leak every allocation they touch is a Very Bad Idea, but so is XORing pointers.

Ironically, if Alloy had done what other Rust GCs do - i.e. have a dedicated Collect trait - you could store x and x^y in a single newtype that transparently recovers y and tells the GC to traverse it. This is the sort of contrived scenario where insisting on API changes to provide a precise collector actually gets what a conservative collector would miss.

[0] If you're wondering what situations in which "cast from pointer and int to another pointer" would be necessary, consider how NaN-boxing or tagged pointers in JavaScript interpreters might be made sound.

Re: Garbage collection for Rust: The finalizer frontier

#116
post #93
post #40

Earlier quoted context omitted.

Pattern matching, usable abstractions, non null types, tagged unions or w/e enums are, build tools etc

Standard ML from 1983, alongside all those influenced by it like Haskell, OCaml, Agda, Rocq,....

Most of those have nothing remotely approaching Rust's level of build tooling.

Re: Garbage collection for Rust: The finalizer frontier

#117
post #40

Earlier quoted context omitted.

Pattern matching, usable abstractions, non null types, tagged unions or w/e enums are, build tools etc

This sounds more like "this is what I like in rust" than "features any modern language should have" though If you like rust, use rust. It's very likely the best rust

> This sounds more like "this is what I like in rust" than "features any modern language should have" though

Good build tooling has been around since 2004, and all of the rest of those features have been around since the late 1970s. There's really no excuse for a language not having all of them.

Re: Garbage collection for Rust: The finalizer frontier

#118

I don’t understand the desire to staple a GC into Rust. If you want this, you might just…want a different language? Which is fine and good! Putting a GC on Rust feels like putting 4WD tyres on a Ferrari sports car and towing a caravan with it. You could (maybe) but it feels like using the wrong tool for the job.

Adding a GC to Rust might honestly be easier than getting the OCaml ecosystem to adopt something that works as well as cargo. It's tragic, but that's the world we live in.

Re: Garbage collection for Rust: The finalizer frontier

#119
post #40

Earlier quoted context omitted.

Pattern matching, usable abstractions, non null types, tagged unions or w/e enums are, build tools etc

This sounds more like "this is what I like in rust" than "features any modern language should have" though If you like rust, use rust. It's very likely the best rust

That’s definitely a list of features that any modern language should have. It’s in no way specific to Rust.

Re: Garbage collection for Rust: The finalizer frontier

#120

I'm curious about the applicability. If memory management is already resolved with the borrow checker rules, then what case can make you want a GC in a Rust program?

> If memory management is already resolved with the borrow checker rules

Even in standard Rust, this only applies to a subset of memory management. That’s why Rust supports reference counting, for example, which is an alternative to borrow checking. But one could make the case that automatic garbage collection was developed specifically to overcome the problems with reference counting. Given that context, GC in Rust makes perfect sense.

Post reply on HN