Performance is one of the top reasons developers choose Rust for
their applications. In fact, it's the first reason listed under the
"Why
Rust?"
section on the rust-lang.org homepage, even before memory
safety. This is for good reason too--many benchmarks show that
software written in Rust is fast, sometimes even the
fastest. This
doesn't mean that everything written in Rust is guaranteed to be
fast, though. In fact, it's surprisingly easy to write slow Rust
code, especially when attempting to appease the borrow checker by
cloning or Arc
-ing instead of borrowing, a strategy which is
generally recommended to new Rust users. That's why it's important
to profile and benchmark Rust code to see where any bottlenecks are
and to fix them, just like you would in any other language. In this
post, I'll demonstrate some basic tools and techniques for doing so,
based on my recent experience working to improve the performance of
the mongodb
crate.