Skip to content

Instantly share code, notes, and snippets.

Last active August 10, 2018 01:56
What would you like to do?
Rust >> C++ #research

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.

Copy link

ghost commented Apr 16, 2017

ty babe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment