Skip to content

Redundant SLOADs in Initializable #4579

@0xVolosnikov

Description

@0xVolosnikov

Opening issue as mentioned in #4576 (comment)

📝 Details

Since InitializableStorage is a struct with two fields packed in one storage slot, compiler need to load this slot when writing new value only for one of the fields, like here:

if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}

Since (when) we know values for other fields, explicit usage of known values can let the compiler to prevent excessive SLOADs before SSTORE. Example:

$._initialized = 1;
$._initializing = false;

PS: this is applicable not only in this place, but also in some other contracts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions