Struct Alignment

Optimization

Struct alignment in Solidity refers to the practice of ordering members within a struct to optimize storage slot usage in the Ethereum Virtual Machine (EVM). The EVM packs variables into 256-bit (32-byte) storage slots. By grouping smaller variables (e.g., uint8, uint16) that collectively fit within a 32-byte boundary, developers can minimize the number of storage slots consumed. This optimization directly reduces gas costs for writing and reading state variables. Efficient alignment is crucial for the economic sustainability of gas-intensive smart contracts.