You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
“Using LLVM” is not a universal solution to all performance problems. While I am not aware of benchmarks comparing performance of C++ and Rust at scale, it’s not to hard to come up with a list of cases where Rust leaves some performance on the table relative to C++.
The biggest one is probably the fact that Rust’s move semantics is based on values (memcpy at the machine code level). In contrast, C++ semantics uses special references you can steal data from (pointers at the machine code level). In theory, compiler should be able to see through chain of copies; in practice it often doesn’t: #57077. A related problem is the absence of placement new — Rust sometimes need to copy bytes to/from the stack, while C++ can construct the thing in place.
Somewhat amusingly, Rust’s default ABI (which is not stable, to make it as efficient as possible) is sometimes worse than that of C: #26494.
Finally, while in theory Rust code should be more efficient due to the significantly richer aliasing information, enabling aliasing-related optimizations triggers LLVM bugs and miscompilations: #54878.
But, to reiterate, these are cherry-picked examples, sometimes the field is tilted the other way. For example, std::unique_ptrhas a performance problem which Rust’s Box lacks.
A potentially bigger issue is that Rust, with its definition time checked generics, is less expressive than C++. So, some C++ template tricks for high performance are not expressible in Rust using a nice syntax.
via GitHub Pages | Websites for you and your projects, hosted directly from your GitHub repository. Just edit, push, and your changes are live.
January 27, 2022 at 09:17PM
The text was updated successfully, but these errors were encountered:
Why Not Rust?
https://ift.tt/3iPgp7A
“Using LLVM” is not a universal solution to all performance problems. While I am not aware of benchmarks comparing performance of C++ and Rust at scale, it’s not to hard to come up with a list of cases where Rust leaves some performance on the table relative to C++.
The biggest one is probably the fact that Rust’s move semantics is based on values (
memcpy
at the machine code level). In contrast, C++ semantics uses special references you can steal data from (pointers at the machine code level). In theory, compiler should be able to see through chain of copies; in practice it often doesn’t: #57077. A related problem is the absence of placement new — Rust sometimes need to copy bytes to/from the stack, while C++ can construct the thing in place.Somewhat amusingly, Rust’s default ABI (which is not stable, to make it as efficient as possible) is sometimes worse than that of C: #26494.
Finally, while in theory Rust code should be more efficient due to the significantly richer aliasing information, enabling aliasing-related optimizations triggers LLVM bugs and miscompilations: #54878.
But, to reiterate, these are cherry-picked examples, sometimes the field is tilted the other way. For example,
std::unique_ptr
has a performance problem which Rust’sBox
lacks.A potentially bigger issue is that Rust, with its definition time checked generics, is less expressive than C++. So, some C++ template tricks for high performance are not expressible in Rust using a nice syntax.
via GitHub Pages | Websites for you and your projects, hosted directly from your GitHub repository. Just edit, push, and your changes are live.
January 27, 2022 at 09:17PM
The text was updated successfully, but these errors were encountered: