Skip to content

Instantly share code, notes, and snippets.

@kvark
Last active August 10, 2018 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kvark/06c96ef8081e2239955b to your computer and use it in GitHub Desktop.
Save kvark/06c96ef8081e2239955b to your computer and use it in GitHub Desktop.
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