2 ms·
> my naive Rust was ~32% faster than my carefully implemented C. One thing that we have noticed in our work on our Rust AV1 encoder, rav1e, is that Rust autov
by derf_ 8y ago
> my naive Rust was ~32% faster than my carefully implemented C.
One thing that we have noticed in our work on our Rust AV1 encoder, rav1e, is that Rust autovectorizes a lot better than C. In particular, it does a better job of proving that slices have nice sizes (e.g., multiples of 8 or 16 elements). That allows it to leave off all of the boilerplate for handling odd sizes. Rust also does not automatically promote every arithmetic operation to an int. That makes working on 8- or 16-bit types a lot more efficient. The stronger type system, memory safety, and the preference for idioms that avoid bounds checks mean the compiler can successfully autovectorize a lot more code than C, too. We used to joke that the only C code that gets autovectorized is the initialization loops that run exactly once and just set everything to zero.
It's still not as good as hand-written SIMD (maybe within a factor of 2), but it's a lot better than no SIMD.
That said, it makes it hard to do straightforward performance comparisons with C, especially for code where you know you will write the hand-written SIMD, but you just haven't gotten to it yet. There is a lot of code like this in a freshly-implemented video encoder. Rust is using a tool, autovectorization, that it won't get to use when you manually vectorize, and C isn't. That threw off a lot of our early attempts at benchmarking Rust vs. C.
Of course, most things are not video encoders, and most code won't be manually vectorized, so the better autovectorization is an absolute win in the real world.
- Const-me 8y ago> Rust autovectorizes a lot better than C What C do you mean? Compilers aren't equal: https://github.com/Const-me/MemoryAccessCosts https://github.com/Const-me/MemoryAccessCosts