|
|
|
|
|
by 0x457
556 days ago
|
|
> Fast Rust demands considerably more thoughtfulness from the programmer (at least for me). While fast code requires thoughtfulness regardless of the language, I think rust lets you focus on the fast aspect more because rustc ensures _some_ safety and correctness. I can write fast and very unsafe C code fast, but I write code that just as fast , but safer in rust faster than in C. |
|
Here's a more concrete, albeit irrelevant in practice example from writing most things in both languages:
https://news.ycombinator.com/item?id=42342382#42352053
Implemented in Rust over generic T, you need Wrapping<T> or the equivalent num_traits traits. The implementations for these take borrowed references. Rustc is pretty good at ensuring this becomes pass by value under the hood, but it's imperfect. I found instances of it failing in the test disassembly, even though an implementation for this never has to touch anything but registers. That's performance work that wouldn't have existed in C/C++ for these particular types.