News for hackers. Stuff that matters.
Re:The Rust Performance Book by anonymousDan on Tuesday November 17, 2020 @08:50AM (#25123675)
'Book' seems a grand title for what could essentially fit in a long blog post? One thing I've been wondering recently is in relation to Rust's overhead for dynamic bounds checks. I know in many cases these can be avoided/elided (e.g. using iterators), but are there any common cases where this isn't possible? Or alternatively where convincing the compiler to remove them introduces a significant amount of complexity?
Re:The Rust Performance Book by __s on Tuesday November 17, 2020 @09:05AM (#25123829)
Book is what this site layout is called in the community, see also:

Rust Book: https://doc.rust-lang.org/book

Rust Rand Book: https://rust-random.github.io/book

Rust WebAssembly Book: https://rustwasm.github.io/book

Rust Unstable Book: https://doc.rust-lang.org/beta/unstable-book/index.html

Rustonomicon: https://doc.rust-lang.org/beta/nomicon/index.html

Cargo Book: https://doc.rust-lang.org/cargo

Which seems to be generated by https://github.com/rust-lang/mdBook

Now, I don't see why "book" should seem so grand. Remember when reference books would come out as a "bible"?

As for bounds check, here's a relevant issue raised on rand crate: https://github.com/rust-random/rand/issues/592

One can dig for a kind of "unsafe assertions" with https://doc.rust-lang.org/std/hint/fn.unreachable_unchecked.... (so the random code, for example, could have before returning value 'if x >= upper { unsafe { unreachable_unchecked() } }')

Re:The Rust Performance Book by trevyn on Tuesday November 17, 2020 @09:09AM (#25123872)
Yep. I'll also add that "books" are typically used for higher-level, more narrative pieces of documentation, vs the API-level `rustdoc`-generated documentation.
Re:The Rust Performance Book by anonymousDan on Tuesday November 17, 2020 @04:22PM (#25130029)
Thanks for the links. If the intention is to expand over time then I agree it makes sense.
Re:The Rust Performance Book by rkangel on Tuesday November 17, 2020 @09:40AM (#25124198)
The expectation for a blog post is that it captures things at a single moment in time. To me, "book" implies something that will be continually updated and maybe expanded.
Re:The Rust Performance Book by staticassertion on Saturday November 21, 2020 @06:41PM (#25173577)
Strange, I feel the opposite, just because of the medium that books tend to be written in - ink.

To me a book has chapters, sequence, etc.

Re:The Rust Performance Book by rkangel on Saturday November 21, 2020 @07:00PM (#25173666)
Yes, it you get multiple editions of books over multiple years, whereas blog posts don't get continuously revised.
Re:The Rust Performance Book by nicoburns on Tuesday November 17, 2020 @09:05AM (#25123836)
If you're really convinced that it's safe to elide them and you can't get it to work using iterators or asserts then you can use `unsafe` to bypass the checks. But I don't think this is necessary in most cases.
Re:The Rust Performance Book by gameswithgo on Tuesday November 17, 2020 @09:03AM (#25123812)
when iterators can’t be used and llvm can’t elide you can use unsafe to elide by hand. the scenarios where the performance matters and iterators can’t be used are thankfully pretty rare so not much unsafe has to be used for this reason.
Re:The Rust Performance Book by vbezhenar on Tuesday November 17, 2020 @09:07AM (#25123853)
Is there any way to treat bounds check as a warning to eliminate it early?
Re:The Rust Performance Book by staticassertion on Saturday November 21, 2020 @06:42PM (#25173580)
A nice method I've found (and seems popular) is to use unsafe but use a debug_assert!. That way your tests will fail loudly if you hit the assertion, but you won't take a hit in production.
Re:The Rust Performance Book by gameswithgo on Tuesday November 17, 2020 @09:25AM (#25124032)
not globally no. isolating that kind of behavior to unsafe blocks is a priority to make it easier to audit. if you wanted globally unsafe memory C or Zig would be a more sensible choice