You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caching returned values from function calls can save gas
2
Cache length in the for loop and uncheck index
1. Caching returned values from function calls can save gas
External call to other contract is gas consuming and should avoid as much as possible.
For example, in Community.lendToProject() function, lenderFee() of _projectInstance is called 2 times. We should call only 1 time and cache the returned values to save gas.
Summary
1. Caching returned values from function calls can save gas
External call to other contract is gas consuming and should avoid as much as possible.
For example, in
Community.lendToProject()
function,lenderFee()
of_projectInstance
is called 2 times. We should call only 1 time and cache the returned values to save gas.Affected Codes
2. Cache length in the for loop and uncheck index
At each iteration of the loop, length is read from storage. We can cache the length and save gas per iteration.
Solidity 0.8.0 check safe math in every operation. Use uncheck to increase index can save gas.
For example
Occurences
The text was updated successfully, but these errors were encountered: