Low-level optimization of algebraic and similar structures
summary
Rust actually changes layouts: zero-sized types occupy 0 bytes and the never type removes whole error variants, structs get field reordering to reduce padding, and enums get pointer/NonZero optimizations plus discriminator flattening for Option-like enums. Code analysis uses a Rust parser over >1,000 enum declarations and finds over 40% enums with zero-field variants and about one in six that “look like Option.” Async state machines get re-layout that can cut future size by 1/3 and reduce previously kilobyte-sized futures.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:08Presentation plan
- 3:30Key operators
- 6:03Empty tuple
- 8:31Never type
- 10:37Multiple optimization
- 16:19Product flattening
- 19:22Statistics
- 20:11Invariants
- 31:24Remarks
- 32:04Questions
- 34:33State machine
- 35:34Zero bit patterns
- 38:16Flattening options
- 39:39Phantom types
related talks
25mType System Tips for the Real World
26mThe Freedom of Static Typing
51mAllocating Less: Really Thin Rust Cloud Apps
26mAllocating Less: Really Thin Rust Cloud Apps
41mFunctional Rust - An Exploration
22mFearless Refactoring
54mAllocating Less: Really Thin Rust Cloud Apps
32mBuilding and Maintaining Rust at Scale
