Reasons why Rust can be faster than C++:
- aliasing information available to compiler (automatic
__restrict
) - one less jump on virtual functions due to traits (Runtime polymorphism)
- undefined struct layout
- reference counting (
Rc<T>
) is lock-free because of being task-local - allocator model: rust provides hints and could inline calls to
jemalloc
(issue, RFC)
It's worth noting that since Rust restricts pointers more than C does, the ordering restrictions on pointers could be relaxed. This hasn't been implemented in LLVM yet since most of the optimization work is based on leveraging the rules of C and C-family languages. Even if they did implement relaxations on the reordering rules, however, storing data in registers will still be easier to optimize.
ty babe