Cache array length in for loops can save gas #115
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
Handle
defsec
Vulnerability details
Impact
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Proof of Concept
Tools Used
None
Recommended Mitigation Steps
Consider to cache array length.
The text was updated successfully, but these errors were encountered: