Engineering Craft · 16 min · free with an account

Profiling First

Lesson preview · about 30%

Measure first: the bottleneck is almost never where it feels like it is.

Core idea

Profile, change one thing, measure again. Guessing is not optimising.

Start with the idea

A profiler shows where time actually goes, and the usual answers are allocation, copying, and syscalls rather than arithmetic. In Rust specifically: check you built with --release, look for clones in a hot loop, prefer with_capacity over repeated growth, and confirm bounds checks are the problem before reaching for unsafe. A benchmark that is not statistically stable is not a benchmark.

Start with a user-visible performance question and a baseline. Is the problem p95 request latency, startup time, battery use, memory footprint, or throughput? These metrics can move in different directions. A release build is necessary for a fair Rust measurement, but it is not enough. Keep input sizes representative, warm caches deliberately, repeat measurements, and record variance. A profiler points to expensive stacks or allocations; it does not automatically tell you which change is safe or worthwhile.

Suppose a hot path clones a vector on every request.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep