Re:When zero cost abstractions aren't zero cost
by celeritascelery on Monday August 09, 2021 @11:22PM
(#28124861)
> 2. Okay, so you don't understand how RefCell works? The caller to this function should be holding r, not passing it into the function. Of course that will just correctly Panic, so it's not wonderful. But that is the point of RefCell.
That’s not the interesting part. The point is that rust won’t optimize a lifetime inside a struct the same way it will optimize an actual reference. It can’t assume that the lifetime will be valid for the whole function (as it can with ref). This limits the amount of reordering you can do in the optimizer.
The example you were looking at was explaining why that is the case.
Re:When zero cost abstractions aren't zero cost
by gridspy on Monday August 09, 2021 @11:26PM
(#28124878)
Okay, thanks for clarifying that.
Ultimately I'm happy for Rust to only be so smart, of course there are going to be limitations. But you are right, the author was making a clear example and my comment doesn't make sense in that context.
Re:When zero cost abstractions aren't zero cost
by spoiler on Tuesday August 10, 2021 @03:03AM
(#28125876)
Isn't this (at least in part) addressed by NLLs[1], or am I misunderstanding?
[1]: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll....
1. Turns out that zeroing u8 is a special case so if you allocate 17 GB of your custom structure Rust is gonna init that for you.
2. Okay, so you don't understand how RefCell works? The caller to this function should be holding r, not passing it into the function. Of course that will just correctly Panic, so it's not wonderful. But that is the point of RefCell.
Generally more stuff runs fast in Rust than in other languages, but you can always find bad counterexamples in any language.