Hacker News new | ask | show | jobs
by pmarcelll 3071 days ago
Last fall I tried to figure out why Rust is slower than D in a base64 benchmark (https://github.com/kostya/benchmarks). It turned out that decoding in Rust is really fast but encoding is a bit slow. I looked at the assembly output of both programs and I could more or less follow the steps in the Rust version, but the D version was only about 5 SIMD instructions (without a single bit shift). I also checked the source code, the Rust version is fairly long, because a part of the hot loop is manually unrolled, but the D version looked like the simple, naive implementation in C. It might be a result of newer LLVM version (LDC was already using LLVM 5 and rustc is still on LLVM 4) or rustc still might have issues with optimizer settings (both binaries were compiled for Intel Haswell).
1 comments

Do you have LLVM IR output? There are definitely places where rust's hinting isn't optimal, and that might not be too difficult to fix.
I didn't look at the LLVM IR (since I'm not really familiar with it), but I might investigate it a bit further in the near future.
I would encourage it. LLVM IR is fairly easy to understand. One of my first forays into rustc was looking at the IR for iterators to see why one version was show (turned out to be that the bounds on the index variable couldn't proven tight enough to eliminate the bounds check, iirc).

Try writing the same simple code as D and compare the two IR representations.

And no matter how much I slag on rust being difficult, the community is really good about helping and teaching.