News for hackers. Stuff that matters.
Re:The Rust Performance Book by kemenaran on Tuesday November 17, 2020 @09:29AM (#25124069)
Nicholas Nethercote is, of course, the author of the "How to speed up the Rust compiler" series of articles [1], which I found fascinating. He spent quite some time at Mozilla optimizing rustc internals.

Kudos for his work, and for making Rust compilation faster for all of us.

^[1]: https://blog.mozilla.org/nnethercote/category/rust/

Re:The Rust Performance Book by OskarS on Tuesday November 17, 2020 @09:23AM (#25124007)
I've skimmed through the book, is there no advice on things like cache locality? Cache misses and the like? SOA instead of AOS? These are like the central issues of high performance code once you get past "maybe don't heap allocate in a hot loop" or whatever.
Re:The Rust Performance Book by couchand on Tuesday November 17, 2020 @09:36AM (#25124138)
It looks like chapters 8 and 16 (at least) obliquely refer to those ideas. Perhaps if there are specific topics you think would be useful, you could open an issue or a PR?

That being said, it looks to me like the main concern here is surfacing Rust specifics, rather than general performance concerns.

Re:The Rust Performance Book by nnethercote on Tuesday November 17, 2020 @05:40PM (#25130893)
The book is primarily about Rust-specific things. Section 1 says: "Some of the techniques within are entirely Rust-specific, and some involve ideas that can be applied (often with modifications) to programs written in other languages." I will clarify this.

Having said that, Section 16 does have general optimization advice, and I will consider adding some brief notes about the things you mentioned there.

Thanks for the suggestion.

Re:The Rust Performance Book by staticassertion on Saturday November 21, 2020 @06:39PM (#25173572)
Those aren't particularly Rust specific, except when Rust constructs make those things easier/ harder, which is how they're brought up.

Someone could explain things like cache via Rust, but the information is language agnostic, whereas this book is very much Rust specific.

Re:The Rust Performance Book by iExploder on Tuesday November 17, 2020 @09:44AM (#25124240)
for the real work you'll have to use C. Rust use case is for crafting cool new age hacker news stories.
Re:The Rust Performance Book by mjb on Tuesday November 17, 2020 @10:40AM (#25125001)
This taught me about ahash (https://crates.io/crates/ahash). It uses the aesenc (https://www.felixcloutier.com/x86/aesenc) instruction as a high-quality fast permutation. Smart and fun.
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