Benchmarking and Optimization of Rust Libraries
summary
Uses cargo bench and benchcmp plus criterion to get reproducible results and statistics, notes cargo bench is nightly only. Shows Postgres numeric serialization via string conversion at ~15,000 ns versus a math-based scaling loop at ~5,000 ns for a 3x speedup. Demonstrates fixed-size slices and inlining cut 3 ns→2 ns and loop times ~3700 ns→2100 ns. Optimizes division from naive 18 ns for small inputs to consistent ~42–46 ns for all sizes, finds copy (≈2900 ns) slower than borrow (≈2400 ns), and observes unsafe shows no benefit in tested cases.
AI-written summary · about
chapters (16)
- 0:00Intro
- 0:59New Zealand Accent 101
- 1:42Growing Ecosystem
- 2:45Micro vs Macro benchmarking
- 10:52Obtaining realistic workloads
- 12:02Back to fundamentals
- 12:29Ex: PostgreSQL write performance
- 12:56E.g. storing the number 3.14
- 13:40Base-10 Implementation
- 14:48Math implementation
- 16:15Performance of math calculations
- 20:24Representing a decimal
- 22:32Exploiting fixed size primitive types
- 25:48Copying vs Borrowing
- 27:19What about unsafe?
- 28:51Closing Thoughts
related talks
27mImproving Rust Performance Through Profiling and Benchmarking
26mAllocating Less: Really Thin Rust Cloud Apps
19mProduction Unsafe Rust
59mParallel Programming in Rust: Techniques for Blazing Speed
38mStrategies to speed up build iteration, or dynamic hot reloading
32mBuilding and Maintaining Rust at Scale
56mReady for Rust
01h 02mRewriting of a small component from C to Rust
