Skip to content
← All Rust tracks

Performance and Data Layout

Rust

Investigate allocations, capacity, data layout and cache behavior. Measure changes and interpret the runtime or allocation checks used by individual exercises.

This track uses Rust. You can make it your practice mode to browse related content across the site.

17 exercises

3 articles

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Benchmarking: measure the work you intend to compare Read
  2. 2 Profiling Rust: finding the hot spot before you optimise it Read
  3. 3 Not solved yet. Where the allocations are: the counting allocator Practice · Easy
  4. 4 Not solved yet. Shrink an enum and inspect its layout Practice · Medium
  5. 5 Not solved yet. Compare Rust and C struct layouts Practice · Medium
  6. 6 Not solved yet. repr(C): computing struct layout by hand Practice · Medium
  7. 7 Not solved yet. The other reprs: transparent, packed, align, integer enums Practice · Hard
  8. 8 Not solved yet. Store and transpose a grid in one flat buffer Practice · Medium
  9. 9 Not solved yet. Build a byte index with one allocation Practice · Easy
  10. 10 Not solved yet. Filter records without cloning their tags Practice · Medium
  11. 11 Not solved yet. Sorting: sort vs sort_unstable vs sort_by_cached_key Practice · Medium
  12. 12 Not solved yet. Bounds checks: five safe ways to express access Practice · Hard
  13. 13 Not solved yet. Compute a dot product with eight accumulator lanes Practice · Hard
  14. 14 SIMD in Rust: what is stable, what is not Read
  15. 15 Not solved yet. Place inline and cold attributes on helper functions Practice · Hard
  16. 16 Not solved yet. Implement a custom hasher for integer keys Practice · Hard
  17. 17 Not solved yet. Build a report with a reusable string buffer Practice · Medium
  18. 18 Not solved yet. Reserve output space and report iterator size hints Practice · Medium
  19. 19 Not solved yet. Const generics: moving a size from runtime to compile time Practice · Hard
  20. 20 Not solved yet. const fn and compile-time evaluation Practice · Hard

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

What does reserving capacity guarantee for the 1,000 pushes into b?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

fn main() {
    let mut a: Vec<u32> = Vec::new();
    let mut b: Vec<u32> = Vec::with_capacity(1000);
    println!("initial lengths: {} {}", a.len(), b.len());
    for value in 0..1000 {
        a.push(value);
        b.push(value);
    }
    println!("final lengths: {} {}", a.len(), b.len());
    println!("same elements: {}", a == b);
}
Question 1 of 4