From 0bcfa9322bb70b19b026ce13895e905dbd782c06 Mon Sep 17 00:00:00 2001 From: bt3gl <1130416+bt3gl@users.noreply.github.com> Date: Mon, 25 Jul 2022 17:30:30 -0700 Subject: [PATCH] Update README.md --- Solidity-Expert/Tricks-to-save-gas/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Solidity-Expert/Tricks-to-save-gas/README.md b/Solidity-Expert/Tricks-to-save-gas/README.md index f5d5ce1..dd3a439 100644 --- a/Solidity-Expert/Tricks-to-save-gas/README.md +++ b/Solidity-Expert/Tricks-to-save-gas/README.md @@ -33,6 +33,16 @@ uint8 numberTwo; uint256 bigNumber; ``` +--- + +### Constant vs. Immutable variables + +Constant values can sometimes be cheaper than immutable values: + +1. 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, allowing local optimizations. +2. 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. + + --- ### Mappings are cheaper than Arrays