4 ms·
Currently Rust doesn't make proper use of its aliasing rules because of bugs in LLVM. This can reduce performance of code by forcing unnecessary memory accesse
by CodesInChaos 7y ago
Currently Rust doesn't make proper use of its aliasing rules because of bugs in LLVM. This can reduce performance of code by forcing unnecessary memory accesses. As an experiment you could try the `-Zmutable-noalias=yes` option, which should enable these optimizations (but exposes you to those bugs). See [masklynn's comment](https://news.ycombinator.com/item?id=20948779 https://news.ycombinator.com/item?id=20948779).
In general Rust suffers a bit because LLVM is primarily a C++ compiler backend. For example infinite loops without side-effects are UB in C++, but supposed to be well defined in Rust. This is even an issue for C, because `while(1) {}` is a valid in C but UB in C++. https://github.com/rust-lang/rust/issues/28728 https://github.com/rust-lang/rust/issues/28728
- emmericp 7y agoYeah, enabling noalias optimizations is on our todo-list. I think that’s one of the most interesting performance features of Rust. It could be the thing that makes Rust faster than C, ultimately. Too bad it‘s so broken in LLVM :(
- masklinn 7y ago> Too bad it‘s so broken in LLVM :( TBF it wasn't just LLVM: in https://github.com/rust-lang/rust/issues/54878 https://github.com/rust-lang/rust/issues/54878 "nikic" and "comex" provided C test cases which failed in both clang[0] and gcc[1]. Though GCC has since fixed the issue while it remains open on LLVM. [0] https://bugs.llvm.org/show_bug.cgi?id=39282 https://bugs.llvm.org/show_bug.cgi?id=39282 [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87609 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87609
- fulafel 7y agoThe infinite-loop Rust issue is old, and the asm "" fix had been known for a long time. I wonder what is behind this seeming perf over correctness decision.