I am working on a project where storage efficiency is of utmost importance. Specifically, I have a scenario where I want to store an ID of type uint16 and a code of type uint8. The current plan is to use these within a struct:

// Requires only 3 bytes;
// but will solidity use all 32 bytes in a storage slot for only a single Info?
struct Info {
    uint16 id;
    uint8 code;

mapping(uint256 => Info[]) internal data;

Given that Ethereum's storage is slot-based (32 bytes), I am curious if, by 2023, there have been any updates in Solidity to natively optimize storage for smaller-sized integer types in structs. I am hoping that it can pack these values efficiently without resorting to manual bitwise operations.

If such a feature or improvement has been introduced, could you guide me to the relevant documentation or changelog? Additionally, if there are any known best practices or workarounds for such scenarios that could help in storage optimization, I would appreciate any insights.

1 Answer 1


How about use 'bytesXX' type ?

Document reference: https://docs.soliditylang.org/en/v0.8.22/types.html#fixed-size-byte-arrays

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.