Storing enum tags after payloads instead of before can significantly reduce memory usage by avoiding alignment padding. Traditional enum layout places tags first, causing alignment requirements to add padding between tag and payload fields. By reversing the order and placing tags last, nested enums can achieve much more compact memory layouts, with Swift being a notable language that implements this optimization.

6m read timeFrom scattered-thoughts.net
Post cover image

Sort: