Optimizing Struct Memory Alignment
Go aligns struct fields based on their size. Large fields should come first to minimize padding bytes added by the compiler to ensure memory address alignment.
type Optimized struct {A int64 // 8 bytesB int32 // 4 bytesC bool // 1 byte} // Total: 16 bytes (3 bytes padding)type Unoptimized struct {C bool // 1 byteA int64 // 8 bytes (7 bytes padding!)B int32 // 4 bytes} // Total: 24 bytes