3 ms·
Yup, in fact everything in Rust is by default a value type, you have to use Box<T> to get a heap allocated value so otherwise it's on the stack and usually pret
by vvanders 8y ago
Yup, in fact everything in Rust is by default a value type, you have to use Box<T> to get a heap allocated value so otherwise it's on the stack and usually pretty memory local.
You've also got things like mem::transmute to let you do the really fun stuff like direct mmap of data structures and other fun(but potentially very platform specific) operations.
In fact it's not turned on by default(but I understand in the works) but the way Rust is designed(single mutable pointer, no aliasing) means that you could turn on restrict[1] by default, which can be a huge performance win in certain circumstances.
[1] http://en.cppreference.com/w/c/language/restrict http://en.cppreference.com/w/c/language/restrict
- steveklabnik 8y agoWe turned it back on quite recently! I haven’t seen any numbers yet though.
- vvanders 8y agoDude! That's awesome, I was under the impression it was a ways away. Is this on nightly or going to be making it into one of the upcoming stable releases?
- steveklabnik 8y agoBoth, it landed a few hours ago, and so will be in 1.28 stable. Here's the PR: https://github.com/rust-lang/rust/pull/50744 https://github.com/rust-lang/rust/pull/50744
- vvanders 8y agoDamn, you guys are knocking it out of the park with Rust. We used to have to do all sorts of convolutions to turn on restrict in the few places it made sense(particle systems, etc). Pretty amazing to have it turned on by default across the whole language.
- steveklabnik 8y agoThanks! It’s a great example of how “less restrictions” doesn’t always mean “fastest code”. In some ways, this specific optimization is the core of what Rust is about.