In this final chapter, we’ll discuss optimization strategies with Rust. Rust’s zero-cost abstractions allow you to confidently write Rust code without thinking too hard about performance. Rust delegates much of its machine code generation to LLVM, which has mature, robust, widely deployed, and well-tested code optimization. Code written in Rust will be fast and well optimized without you spending time hand-tuning code.
There are, however, certain cases in which you may need to dive deeper, which we’ll discuss, along with the tools you’ll need, in this chapter. We’ll also discuss how you can use Rust to accelerate code from other languages, which is a fun way to introduce Rust into codebases without needing to perform a complete rewrite.
An important feature of Rust is its zero-cost abstractions. In short, Rust’s abstractions allow you to write high-level code, which produces optimized machine code with no additional runtime overhead. Rust’s compiler takes care of figuring out how to get from high-level Rust to low-level machine code in the optimal way, without the overhead. You can safely use Rust’s abstractions without needing to worry about whether they will create a performance trap.