Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
nnethercote.github.io
Sometimes I pick a crate in the Rust compiler and read through its code to learn about it and find things that I can improve. Often the improvements are small, but sometimes they snowball. One example involved the rustc_errors crate. rustc...
Observations/Thoughts 2024-12-25 ~11 min read
nnethercote.github.io
The Rust Performance Book First published in November 2020 Written by Nicholas Nethercote and others Source code
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Introduction Performance is important for many Rust programs. This book contains techniques that can improve the performance-related characteristics of Rust programs, such as runtime speed, memory usage, and binary size. The Compile Times s...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Benchmarking Benchmarking typically involves comparing the performance of two or more programs that do the same thing. Sometimes this might involve comparing two or more different programs, e.g. Firefox vs Safari vs Chrome. Sometimes it inv...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Build Configuration You can drastically change the performance of a Rust program without changing its code, just by changing its build configuration. There are many possible build configurations for each Rust program. The one chosen will af...
The Rust Performance Book Book 2024-01-01 ~12 min read
nnethercote.github.io
Linting Clippy is a collection of lints to catch common mistakes in Rust code. It is an excellent tool to run on Rust code in general. It can also help with performance, because a number of the lints relate to code patterns that can cause s...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Profiling When optimizing a program, you also need a way to determine which parts of the program are "hot" (executed frequently enough to affect runtime) and worth modifying. This is best done via profiling. Profilers There are many differe...
The Rust Performance Book Book 2024-01-01 ~3 min read
nnethercote.github.io
Inlining Entry to and exit from hot, uninlined functions often accounts for a non-trivial fraction of execution time. Inlining these functions removes these entries and exits and can enable additional low-level optimizations by the compiler...
The Rust Performance Book Book 2024-01-01 ~2 min read
nnethercote.github.io
Hashing HashSet and HashMap are two widely-used types and there are ways to make them faster. Alternative Hashers The default hashing algorithm is not specified, but at the time of writing the default is an algorithm called SipHash 1-3. Thi...
The Rust Performance Book Book 2024-01-01 ~2 min read
nnethercote.github.io
Heap Allocations Heap allocations are moderately expensive. The exact details depend on which allocator is in use, but each allocation (and deallocation) typically involves acquiring a global lock, doing some non-trivial data structure mani...
The Rust Performance Book Book 2024-01-01 ~12 min read
nnethercote.github.io
Type Sizes Shrinking oft-instantiated types can help performance. For example, if memory usage is high, a heap profiler like DHAT can identify the hot allocation points and the types involved. Shrinking these types can reduce peak memory us...
The Rust Performance Book Book 2024-01-01 ~4 min read
nnethercote.github.io
Standard Library Types It is worth reading through the documentation for common standard library types—such as Vec, Option, Result, and Rc/Arc—to find interesting functions that can sometimes be used to improve performance. It is also worth...
The Rust Performance Book Book 2024-01-01 ~2 min read
nnethercote.github.io
Iterators collect and extend Iterator::collect converts an iterator into a collection such as Vec, which typically requires an allocation. You should avoid calling collect if the collection is then only iterated over again. For this reason,...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Bounds Checks By default, accesses to container types such as slices and vectors involve bounds checks in Rust. These can affect performance, e.g. within hot loops, though less often than you might expect. There are several safe ways to cha...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
I/O
I/O Locking Rust's print! and println! macros lock stdout on every call. If you have repeated calls to these macros it may be better to lock stdout manually. For example, change this code: # let lines = vec!["one", "two", "three"]; for line...
The Rust Performance Book Book 2024-01-01 ~2 min read
nnethercote.github.io
Logging and Debugging Sometimes logging code or debugging code can slow down a program significantly. Either the logging/debugging code itself is slow, or data collection code that feeds into logging/debugging code is slow. Make sure that n...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Wrapper Types Rust has a variety of "wrapper" types, such as RefCell and Mutex, that provide special behavior for values. Accessing these values can take a non-trivial amount of time. If multiple such values are typically accessed together,...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Machine Code When you have a small piece of very hot code it may be worth inspecting the generated machine code to see if it has any inefficiencies, such as removable bounds checks. The Compiler Explorer website is an excellent resource whe...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
Parallelism Rust provides excellent support for safe parallel programming, which can lead to large performance improvements. There are a variety of ways to introduce parallelism into a program and the best way for any program will depend gr...
The Rust Performance Book Book 2024-01-01 ~1 min read
nnethercote.github.io
General Tips The previous sections of this book have discussed Rust-specific techniques. This section gives a brief overview of some general performance principles. As long as the obvious pitfalls are avoided (e.g. using non-release builds)...
The Rust Performance Book Book 2024-01-01 ~2 min read
"There actually are NOT very many places where the C code’s behavior conflicts with Rust’s borrowing rules. This is both somewhat surprising, becau..."

Search tips

Type anything to search across articles, videos (including conference talks), podcasts, research, crates, and Rust API documentation. These operators give you finer control — click an example to try it.

Find pages containing all your words. Pages where the words appear together rank higher.
Quote part of your query to keep those words together as an exact phrase within a larger search.
Wrap the whole query in quotes for a verbatim search that matches text exactly, punctuation and all — perfect for Rust syntax. Needs at least 3 characters.
Put ! first to open the top result immediately. Quote the whole query for a literal leading bang, as in '!Send'. Bangs elsewhere, such as println!, stay literal. Browser and launcher shortcuts can invoke this directly. See search integrations.
Limit results to a single site. Works on its own () too. One site: per search.

Use the tabs and filters above the results to narrow by content type, publication year, and sort order.