
PSA: You too can pack structs
Speaker: Nicola Papale
Description
This is an introductory talk. It is aimed at people that are not familiar with struct packing.
Struct packing is useful in a variety of situation, being aware of it can help reduce code complexity and improve performance. Yet, I’ve come across many rust developers who aren’t familiar with struct packing.
This talk presents struct packing, and crates available on crates.io that people may not be aware of, but should really use.
I first introduce how rust layouts structs.
Then I introduce motivating use cases.
Then I show how it is possible to implement it by hand, then using bitflags
.
Then I introduce how C solves this.
Then I explain the pitfalls of the C solution and hint at a “good” solution.
Finally, I introduce the crates specialized in struct packing.
The crates in questions are:
bitbybit
bilge
modular-bitfield
The motivating use cases include:
- Reducing hashing cost
- Interop with hardware and network protocols
- Very simple programming language bytecode
I will mention #[repr(packed)]
only as something not to do.
Track
Technology & Community
Level
Introductory and overview