Struct layout analyzer
See how C, Rust and Go lay out a struct. Find padding, trace 64-byte cache lines and compare the smallest field order.
Runs in your browser or terminal. Your declarations stay on your device.
- Targets
- x86_64, ARM64 and wasm32
HttpRequestRust · repr(C)
#[repr(C)]
struct HttpRequest {
ready: bool,
body: *const u8,
method: u8,
consumed: usize,
status: u16,
scratch: [u8; 36],
retry: bool,
deadline_ns: u64,
}
80 BStruct size
15 BPadding
2Cache lines
Optimal order
80 B72 B
8 bytes saved per struct
Struct padding budgets
Run the same parser and ABI rules from Node. Give a struct a padding budget and let the exit code decide whether CI passes.
$ node bin/packline.mjs check \
--preset http-request --max-waste-pct 19
HttpRequest (x86_64): 80 B, alignment 8 B,
15 B padding (18.75%)
Padding: 15 B interior, 0 B tail, 0 B nested
Cache: 2 × 64 B, 50.78% payload utilization
PASS max waste 19%
0 Within budget1 Input error2 Over budget
Struct layouts and byte maps
-
Find struct offsets
Pick the target ABI to see field sizes, alignment and padding, including gaps inside nested structs.
Field Offset Size Pad ready 0 B 1 B 0 B body 8 B 8 B 7 B method 16 B 1 B 0 B consumed 24 B 8 B 7 B -
Compare field orders
Mark the fields you read together. Packline finds the smallest layout and prefers orders that touch fewer hot cache lines.
80 B→72 B -
Export a byte map
Save an SVG showing which bytes hold data, where padding sits and which fields span a cache-line boundary.
Field bytePadding byte