mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9510 from ethereum/gasImumtable
Explain gas implications of constant and immutable variables.
This commit is contained in:
commit
56e4e9f0af
@ -12,6 +12,14 @@ for ``immutable``, it can still be assigned at construction time.
|
||||
The compiler does not reserve a storage slot for these variables, and every occurrence is
|
||||
replaced by the respective value.
|
||||
|
||||
Compared to regular state variables, the gas costs of constant and immutable variables
|
||||
are much lower. For a constant variable, the expression assigned to it is copied to
|
||||
all the places where it is accessed and also re-evaluated each time. This allows for local
|
||||
optimizations. Immutable variables are evaluated once at construction time and their value
|
||||
is copied to all the places in the code where they are accessed. For these values,
|
||||
32 bytes are reserved, even if they would fit in fewer bytes. Due to this, constant values
|
||||
can sometimes be cheaper than immutable values.
|
||||
|
||||
Not all types for constants and immutables are implemented at this time. The only supported types are
|
||||
`strings <strings>`_ (only for constants) and `value types <value-types>`_.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user