Multiple mappings of same key can be combined into a single mapping to a struct, where appropriate
Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot
Use calldata instead of memory for external functions where the function argument is read-only
The memory keyword in a function argument causes the underlying code to copy the argument into memory. Calldata causes the code to read the transaction without copying it directly, ultimately saves gases.
Multiple
mappings of samekey
can be combined into asingle
mapping to astruct
, where appropriateSaves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot
UNUSED NAMED RETURNS
Using both named returns and a return statement isn’t necessary. Removing one of those can improve code clarity:
Use
calldata
instead ofmemory
forexternal
functions where the function argument isread-only
The
memory
keyword in a function argument causes the underlying code to copy the argument into memory.Calldata
causes the code to read the transaction without copying it directly, ultimately saves gases.internal
functions not called by the contract should be removed to save deployment gasinternal
functions only called once can be inlined to save gas