Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips for Rust Optimization and Profiling

  1. std::mem::size_of returns the stack size of a type.

  2. memuse contains traits for measuring the dynamic memory usage of Rust types.

  3. The Rust Performance Book has a comprehensive guide on optimizing Rust code. Rust Performance Pitfalls discusses about some performance pitfalls that you want to avoid.

  4. rustfilt demangles Rust symbol names using rustc-demangle .

CPU Profiling

CPU profiling tools for Rust applications

Tool

Status

Rust-internal

Cargo / benchmark integration

Install & use

Speed

Comments

samply

Active

No (standalone command-line profiler)

None

Easy

—

Uses the Firefox profiler as its UI

pprof

Active

Yes (Rust crate)

Yes — integrates with Criterion; profile via cargo bench --bench bench_main <name> -- --profile-time (see criterion.rs example)

Easy (added as a crate dependency)

—

Internal perf tool; Criterion benchmarks by default, so --profile-time is needed to emit a profiling report

Valgrind

Active

No

Yes — via cargo-valgrind

Easy to install, configure and use

Slow

Much slower than not-perf

FlameGraph

Low activity (last commit 2024)

No (based on Linux perf)

Yes — has cargo support

Hardest to install, configure and use

—

Relies on Linux perf

puffin

Active

Yes (Rust crate)

—

—

—

Friendly little instrumentation profiler for Rust

not-perf

Inactive (last commit 2023)

No (standalone sampling profiler for Linux)

None

Very easy; no special configuration required

Fast

Memory Profiling

Memory profiling tools for Rust applications

Tool

Status

Rust-internal

Cargo / benchmark integration

Install & use

Speed

Comments

DHAT

Active

No (ships with Valgrind)

None

—

—

Dynamic heap analysis tool that comes with Valgrind

heaptrack

Active

No (standalone profiler for Linux)

None

—

—

Heap memory profiler for Linux

dhat-rs

Low activity (last commit 2025)

Yes (Rust crate)

Yes — used as a crate dependency

Easy (added as a crate dependency)

—

Heap and ad hoc profiling, similar to Valgrind’s DHAT

bytehound

Inactive (last commit 2023)

No (standalone memory profiler for Linux)

None

—

—

References