| ▲ | pizlonator 14 hours ago | |
It's not binary. If you try hard enough, I bet you can make an argument that C is faster and you can make an argument that Rust is faster. There is a set of programs that you can write in C and that are correct, that you cannot write in Rust without leaning into unsafe code. So if by "Rust" we mean "the safe subset of Rust", then this implies that there must be optimal algorithms that can be written in C but not in Rust. On the other hand, Rust's ownership semantics are like rocket fuel for the compiler's understanding of aliasing. The inability of compilers to track aliasing precisely is a top inhibitor of load elimination in C compilers (so much so that C compiler writers lean into shady nonsense like strict aliasing, and even that doesn't buy very much precision). But a Rust compiler doesn't need to rely on shady imprecise nonsense. Therefore, there are surely algorithms that, if written in a straightforward way in both Rust and C, will be faster in Rust. I could even imagine there are algorithms for which it would be very unnatural to write the C code in a way that matches Rust's performance. I'm purely speaking theoretically, I have no examples of either case. Just trying to provide my PL/compiler perspective | ||
| ▲ | umanwizard 14 hours ago | parent [-] | |
> There is a set of programs that you can write in C and that are correct, that you cannot write in Rust without leaning into unsafe code. So if by "Rust" we mean "the safe subset of Rust" Well, unsafe rust is part of rust. So no, we don’t mean that. | ||